From: Josef 'Jeff' Sipek Date: Thu, 4 Mar 2021 21:51:46 +0000 (-0500) Subject: lib-lua: Move compat macros and prototypes to dlua-compat.h X-Git-Tag: 2.3.15~292 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2354db8607f06c742f97ee52fd5574c3444f8118;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Move compat macros and prototypes to dlua-compat.h Additionally, fix -Wstrict-bool issue in luaL_newmetatable() compatibility wrapper. --- diff --git a/src/lib-lua/dlua-compat.h b/src/lib-lua/dlua-compat.h index f1e564d5d0..f53b7009b7 100644 --- a/src/lib-lua/dlua-compat.h +++ b/src/lib-lua/dlua-compat.h @@ -5,6 +5,23 @@ * In general, make whatever Lua version we have behave more like Lua 5.3. */ +/* functionality missing from <= 5.2 */ +#if LUA_VERSION_NUM <= 502 +# define luaL_newmetatable(L, tn) \ + ((luaL_newmetatable(L, tn) != 0) ? \ + (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : \ + 0) +#endif + +/* functionality missing from <= 5.1 */ +#if LUA_VERSION_NUM <= 501 +# define lua_load(L, r, s, fn, m) lua_load(L, r, s, fn) +# define luaL_newlibtable(L, l) (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) +# define luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) +void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); +void luaL_setmetatable (lua_State *L, const char *tname); +#endif + #ifndef HAVE_LUA_ISINTEGER /* * Lua 5.3 can actually keep track of intergers vs. numbers. As a diff --git a/src/lib-lua/dlua-script-private.h b/src/lib-lua/dlua-script-private.h index f14d221e97..edbfb6b8cf 100644 --- a/src/lib-lua/dlua-script-private.h +++ b/src/lib-lua/dlua-script-private.h @@ -6,16 +6,6 @@ #include "lauxlib.h" #include "dlua-compat.h" -#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 -#define luaL_newmetatable(L, tn) \ - (luaL_newmetatable(L, tn) ? (lua_pushstring(L, tn), lua_setfield(L, -2, "__name"), 1) : 0) -#define luaL_newlibtable(L, l) (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) -#define luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_register(L, NULL, l)) -#define lua_load(L, r, s, fn, m) lua_load(L, r, s, fn) -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); -void luaL_setmetatable (lua_State *L, const char *tname); -#endif - /* consistency helpers */ #define lua_isstring(L, n) (lua_isstring(L, n) == 1) #define lua_isnumber(L, n) (lua_isnumber(L, n) == 1)