From 4e52438c0ba3603a597e9d81ea7737071fe8acc3 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Fri, 29 Nov 2024 07:33:51 +0100 Subject: [PATCH] BUG/MINOR: hlua_fcn: fix Patref:set() force parameter Patref:set(key, val[, force]) takes optional "force" parameter (defaults to false) to force the entry to be created if it doesn't already exist To retrieve the value, lua_tointeger() was used in place of lua_toboolean(), and because of that force is not enabled if "true" is passed as parameter (only numbers were recognized) despite the documentation mentioning that "force" is a boolean. To fix the issue, we replace lua_tointeger by lua_toboolean. Also, the doc was updated to rename "bool" to "boolean" for the "force" parameter to stay consistent with historical naming in the file. No backport needed unless 9ee37de5c ("MINOR: hlua_fcn: add Patref:set()") is. --- doc/lua-api/index.rst | 2 +- src/hlua_fcn.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index c16a07e6c..e0afaffcd 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -3558,7 +3558,7 @@ Patref class :param string key: the string used as a key :param string value: the string used as value - :param bool force: create the entry if it doesn't exist (optional, + :param boolean force: create the entry if it doesn't exist (optional, defaults to false) :returns: true on success and nil on failure (followed by an error message) diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 3118e40d5..b6252fbf1 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -2889,7 +2889,7 @@ int hlua_patref_set(lua_State *L) value = luaL_checkstring(L, 3); if (lua_gettop(L) == 4) - force = lua_tointeger(L, 4); + force = lua_toboolean(L, 4); HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->ptr->lock); if ((ref->flags & HLUA_PATREF_FL_GEN) &&