From: Siavash Tavakoli Date: Thu, 12 Aug 2021 18:40:22 +0000 (+0100) Subject: lib-lua: Add lua_resume_compat() and use it in lua versions prior to 5.4 X-Git-Tag: 2.3.17~197 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72a864b4b041e3a4c597a5eeafe3bdc50ffa6dd5;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Add lua_resume_compat() and use it in lua versions prior to 5.4 Starting lua 5.4 "lua_resume()" expects an extra "nresults" argument. Add a compatibility function to handle this argument in earlier versions. --- diff --git a/src/lib-lua/dlua-compat.c b/src/lib-lua/dlua-compat.c index 19b43df430..94f27bac4b 100644 --- a/src/lib-lua/dlua-compat.c +++ b/src/lib-lua/dlua-compat.c @@ -146,3 +146,12 @@ lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum_r) return 0; } #endif + +#if LUA_VERSION_NUM < 504 +# undef lua_resume +int lua_resume_compat(lua_State *L, lua_State *from, int nargs, int *nresults) +{ + *nresults = 1; + return lua_resume(L, from, nargs); +} +#endif diff --git a/src/lib-lua/dlua-compat.h b/src/lib-lua/dlua-compat.h index 6204429c85..307ae467b8 100644 --- a/src/lib-lua/dlua-compat.h +++ b/src/lib-lua/dlua-compat.h @@ -56,4 +56,14 @@ void lua_seti(lua_State *L, int index, lua_Integer n); lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum_r); #endif +#if LUA_VERSION_NUM < 504 +/* + * lua_resume() compatibility function. Lua 5.4 expects an extra "nresults" + * argeument. + */ +# define lua_resume(L, from, nargs, nresults) \ + lua_resume_compat(L, from, nargs, nresults) +int lua_resume_compat(lua_State *L, lua_State *from, int nargs, int *nresults); +#endif + #endif diff --git a/src/lib-lua/dlua-resume.c b/src/lib-lua/dlua-resume.c index 1e792558a4..ac46f1026e 100644 --- a/src/lib-lua/dlua-resume.c +++ b/src/lib-lua/dlua-resume.c @@ -106,7 +106,7 @@ static void queue_resume_callback(lua_State *L, int status) static void dlua_pcall_yieldable_continue(lua_State *L) { struct timeout *to; - int nargs; + int nargs, nresults; int ret; nargs = dlua_tls_get_int(L, RESUME_NARGS); @@ -117,7 +117,7 @@ static void dlua_pcall_yieldable_continue(lua_State *L) dlua_tls_clear(L, RESUME_TIMEOUT); dlua_tls_clear(L, RESUME_NARGS); - ret = lua_resume(L, L, nargs); + ret = lua_resume(L, L, nargs, &nresults); if (ret == LUA_YIELD) { /* * thread yielded - nothing to do @@ -157,6 +157,7 @@ int dlua_pcall_yieldable(lua_State *L, const char *func_name, int nargs, { struct dlua_pcall_resume_state *state; int ret; + int nresults; i_assert(lua_status(L) == LUA_OK); @@ -180,7 +181,7 @@ int dlua_pcall_yieldable(lua_State *L, const char *func_name, int nargs, lua_insert(L, -(nargs + 1)); /* stack: func, args (top) */ - ret = lua_resume(L, L, nargs); + ret = lua_resume(L, L, nargs, &nresults); if (ret == LUA_YIELD) { /* * thread yielded - nothing to do