]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Define lua_isinteger as boolean function
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 May 2021 16:21:50 +0000 (19:21 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 12 May 2021 09:06:46 +0000 (09:06 +0000)
src/lib-lua/dlua-script-private.h
src/lib-lua/dlua-script.c
src/lib-lua/test-lua.c

index f15f883494373ca290f7e4c30a1791f3b27bdda9..32c9ab6e29df619a3f371ecfb9ca48c2341faa32 100644 (file)
@@ -11,6 +11,7 @@
 #define lua_isnumber(L, n) (lua_isnumber((L), (n)) == 1)
 #define lua_toboolean(L, n) (lua_toboolean((L), (n)) == 1)
 #define lua_pushboolean(L, b) lua_pushboolean((L), (b) ? 1 : 0)
+#define lua_isinteger(L, n) (lua_isinteger((L), (n)) == 1)
 
 #define DLUA_TABLE_STRING(n, val) { .name = (n),\
                                    .type = DLUA_TABLE_VALUE_STRING, .v.s = (val) }
index 3dfc3bb241eab31ff219bda516e81c60f449b8c4..822eb0ca83b5aed119cc1f47b0a7665dac337a7d 100644 (file)
@@ -171,7 +171,7 @@ int dlua_script_init(struct dlua_script *script, const char **error_r)
        if (dlua_pcall(script->L, LUA_SCRIPT_INIT_FN, 0, 1, error_r) < 0)
                return -1;
 
-       if (lua_isinteger(script->L, -1) == 1) {
+       if (lua_isinteger(script->L, -1)) {
                ret = lua_tointeger(script->L, -1);
                if (ret != 0)
                        *error_r = "Script init failed";
index 7a28014d9c11855742c5870eb5187be7a0731e57..59a669d2ef68673319486d055a9f7691c1a212b5 100644 (file)
@@ -357,7 +357,7 @@ static void test_tls(void)
 
 /* check lua_tointegerx against top-of-stack item */
 static void check_tointegerx_compat(lua_State *L, int expected_isnum,
-                                   int expected_isint,
+                                   bool expected_isint,
                                    lua_Integer expected_value)
 {
        lua_Integer value;
@@ -430,18 +430,18 @@ static void test_compat_tointegerx_and_isinteger(void)
 
        for (i = 0; i < N_ELEMENTS(str_tests); i++) {
                lua_pushstring(script->L, str_tests[i].input);
-               check_tointegerx_compat(script->L, str_tests[i].isnum, 0,
+               check_tointegerx_compat(script->L, str_tests[i].isnum, FALSE,
                                        str_tests[i].output);
        }
 
        for (i = 0; i < N_ELEMENTS(num_tests); i++) {
-               int isint;
+               bool isint;
 
                /* See lua_isinteger() comment in dlua-compat.h */
 #if LUA_VERSION_NUM == 503
-               isint = 0;
+               isint = FALSE;
 #else
-               isint = num_tests[i].isnum;
+               isint = (num_tests[i].isnum == 1);
 #endif
 
                lua_pushnumber(script->L, num_tests[i].input);
@@ -452,7 +452,7 @@ static void test_compat_tointegerx_and_isinteger(void)
 
        for (i = 0; i < N_ELEMENTS(int_tests); i++) {
                lua_pushinteger(script->L, int_tests[i].input);
-               check_tointegerx_compat(script->L, 1, 1,
+               check_tointegerx_compat(script->L, 1, TRUE,
                                        int_tests[i].output);
        }