commit 35818ae: [Minor] Lua core: Add some missing compat functions

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Sep 16 12:21:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-16 12:31:13 +0100
URL: https://github.com/rspamd/rspamd/commit/35818aec2c5f6e70423fa2954fc9a344b5fe56f0

[Minor] Lua core: Add some missing compat functions

---
 src/lua/lua_common.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

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)


More information about the Commits mailing list