]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Implement lua_seti() fallback for pre-5.3 support
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Thu, 25 Feb 2021 20:35:26 +0000 (15:35 -0500)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 19 Mar 2021 13:13:10 +0000 (15:13 +0200)
m4/want_lua.m4
src/lib-lua/dlua-compat.c
src/lib-lua/dlua-compat.h

index 937a1493505053e4f71cbdbd0a839f3f2d37e51a..d1cec03a3043333c1eb417008d55e7dba0af3c6e 100644 (file)
@@ -49,6 +49,7 @@ AC_DEFUN([DOVECOT_WANT_LUA],[
    AC_CHECK_FUNCS([luaL_setmetatable])
    AC_CHECK_FUNCS([lua_isinteger])
    AC_CHECK_FUNCS([lua_resume])
+   AC_CHECK_FUNCS([lua_seti])
    AC_CHECK_FUNCS([lua_tointegerx])
    AC_CHECK_FUNCS([lua_yieldk])
 
index 67f83db3aea8583b8d61c52497958f16b40e366a..b0635741e6a665de6f5517c466e53653ee6e4e33 100644 (file)
@@ -54,6 +54,23 @@ int lua_isinteger(lua_State *L, int idx)
 }
 #endif
 
+#ifndef HAVE_LUA_SETI
+void lua_seti(lua_State *L, int index, lua_Integer n)
+{
+       /* stack: value (top) */
+       lua_pushinteger(L, n);
+       /* stack: value, n (top) */
+       lua_insert(L, -2);
+       /* stack: n, value (top) */
+
+       /* adjust relative stack position */
+       if (index < 0)
+               index--;
+
+       lua_settable(L, index);
+}
+#endif
+
 #ifndef HAVE_LUA_TOINTEGERX
 #  if LUA_VERSION_NUM >= 502
 #    error "Lua 5.2+ should have lua_tointegerx()"
index c972ef93d2402a3ce258fa34da5c08142af2ba6e..e41509656610e22de870d73a88ba88197594496d 100644 (file)
@@ -40,6 +40,10 @@ void luaL_setmetatable (lua_State *L, const char *tname);
 int lua_isinteger(lua_State *L, int idx);
 #endif
 
+#ifndef HAVE_LUA_SETI
+void lua_seti(lua_State *L, int index, lua_Integer n);
+#endif
+
 #ifndef HAVE_LUA_TOINTEGERX
 /*
  * Lua 5.2 and 5.3 both have lua_tointegerx(), but their behavior is subtly