From 2a7ad799437105f91dfe7e89ba50de655c1d06eb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 21 Apr 2020 16:07:25 +0100 Subject: [PATCH] [Minor] Add lua_geti compat method --- src/lua/lua_common.c | 14 +++++++++++++- src/lua/lua_common.h | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 9c4a5d8d1..d53ebbc48 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -2539,4 +2539,16 @@ rspamd_lua_universal_pcall (lua_State *L, gint cbref, const gchar* strloc, va_end (ap); return true; -} \ No newline at end of file +} + +#if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 +gint +rspamd_lua_geti (lua_State *L, int pos, int i) +{ + pos = lua_absindex (L, pos); + lua_pushinteger (L, i); + lua_gettable (L, pos); + + return lua_type (L, -1); +} +#endif \ No newline at end of file diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 296b8f326..f9ec8e2e3 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -605,6 +605,19 @@ gchar *rspamd_lua_get_module_name (lua_State *L); bool rspamd_lua_universal_pcall (lua_State *L, gint cbref, const gchar* strloc, gint nret, const gchar *args, GError **err, ...); +/** + * Wrapper for lua_geti from lua 5.3 + * @param L + * @param index + * @param i + * @return + */ +#if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 +gint rspamd_lua_geti (lua_State *L, int index, int i); +#else +#define rspamd_lua_geti lua_geti +#endif + /* Paths defs */ #define RSPAMD_CONFDIR_INDEX "CONFDIR" #define RSPAMD_LOCAL_CONFDIR_INDEX "LOCAL_CONFDIR" -- 2.39.5