]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Add lua_resume_compat() and use it in lua versions prior to 5.4
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Thu, 12 Aug 2021 18:40:22 +0000 (19:40 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 17 Aug 2021 07:49:37 +0000 (07:49 +0000)
Starting lua 5.4 "lua_resume()" expects an extra "nresults" argument. Add a
compatibility function to handle this argument in earlier versions.

src/lib-lua/dlua-compat.c
src/lib-lua/dlua-compat.h
src/lib-lua/dlua-resume.c

index 19b43df430371c0adf2a412ce4b56c9b27ddea49..94f27bac4b39098295f1a3370be7114fb32b9d6b 100644 (file)
@@ -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
index 6204429c85a474b2fc051696602e93170f16d1b6..307ae467b8fa265ad57e4aa3899d97216fb10212 100644 (file)
@@ -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
index 1e792558a494f53b721d523f36668471db31c5ef..ac46f1026e2d8cd061a4b72d8f7310a9f793fb35 100644 (file)
@@ -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