]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua core: Add some missing compat functions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 16 Sep 2019 11:31:13 +0000 (12:31 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 16 Sep 2019 11:31:13 +0000 (12:31 +0100)
src/lua/lua_common.h

index 507925e80201af54c1669cd00d07001093c2a814..265775835be5824c81de223e35e539deeef6d344 100644 (file)
@@ -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)