From: Josef 'Jeff' Sipek Date: Thu, 25 Feb 2021 20:35:26 +0000 (-0500) Subject: lib-lua: Implement lua_seti() fallback for pre-5.3 support X-Git-Tag: 2.3.15~171 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77cb890b16d3f3bbde9fc13c6170728b2ca7a9cf;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Implement lua_seti() fallback for pre-5.3 support --- diff --git a/m4/want_lua.m4 b/m4/want_lua.m4 index 937a149350..d1cec03a30 100644 --- a/m4/want_lua.m4 +++ b/m4/want_lua.m4 @@ -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]) diff --git a/src/lib-lua/dlua-compat.c b/src/lib-lua/dlua-compat.c index 67f83db3ae..b0635741e6 100644 --- a/src/lib-lua/dlua-compat.c +++ b/src/lib-lua/dlua-compat.c @@ -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()" diff --git a/src/lib-lua/dlua-compat.h b/src/lib-lua/dlua-compat.h index c972ef93d2..e415096566 100644 --- a/src/lib-lua/dlua-compat.h +++ b/src/lib-lua/dlua-compat.h @@ -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