From: Vsevolod Stakhov Date: Mon, 16 Sep 2019 11:31:13 +0000 (+0100) Subject: [Minor] Lua core: Add some missing compat functions X-Git-Tag: 2.0~207 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35818aec2c5f6e70423fa2954fc9a344b5fe56f0;p=rspamd.git [Minor] Lua core: Add some missing compat functions --- diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 507925e80..265775835 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -40,6 +40,28 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods) } #endif +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 +static inline int lua_absindex (lua_State *L, int i) { + if (i < 0 && i > LUA_REGISTRYINDEX) + i += lua_gettop(L) + 1; + return i; +} +static inline int lua_rawgetp (lua_State *L, int i, const void *p) { + int abs_i = lua_absindex(L, i); + lua_pushlightuserdata(L, (void*)p); + lua_rawget(L, abs_i); + return lua_type(L, -1); +} + +static inline void lua_rawsetp (lua_State *L, int i, const void *p) { + int abs_i = lua_absindex(L, i); + luaL_checkstack(L, 1, "not enough stack slots"); + lua_pushlightuserdata(L, (void*)p); + lua_insert(L, -2); + lua_rawset(L, abs_i); +} +#endif + /* Interface definitions */ #define LUA_FUNCTION_DEF(class, name) static int lua_ ## class ## _ ## name ( \ lua_State * L)