From 82ee3fb2f83441c8b8e06e5fba9b9268d8d9db1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sat, 19 Mar 2016 13:16:31 +0000 Subject: [PATCH] [mod_magnet] define lua_pushglobaltable (for lua5.1) and use it (fixes #2719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Stefan Bühler git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3106 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/mod_magnet.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 9756b267..758c30d3 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ NEWS * [core] configparser: error on duplicate keys in array merge (fixes #2685) * [core] more careful parse of $SERVER["socket"] config str (prepare #2204) * [core] accept $SERVER["socket"] without port, use server.port as fallback (fixes #2204) + * [mod_magnet] define lua_pushglobaltable (for lua5.1) and use it (fixes #2719) - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 114d41e6..b53a621a 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -162,13 +162,12 @@ static int mod_magnet_patch_connection(server *srv, connection *con, plugin_data } #undef PATCH -static void magnet_get_global_table(lua_State *L) { /* (-0, +1, e) */ -#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 - lua_geti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); -#else +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 +/* lua5.1 backward compat definition */ +static void lua_pushglobaltable(lua_State *L) { /* (-0, +1, -) */ lua_pushvalue(L, LUA_GLOBALSINDEX); -#endif } +#endif static void magnet_setfenv_mainfn(lua_State *L, int funcIndex) { /* (-1, 0, -) */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 @@ -955,7 +954,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu #endif lua_newtable(L); /* the meta-table for the new env (sp += 1) */ - magnet_get_global_table(L); /* (sp += 1) */ + lua_pushglobaltable(L); /* (sp += 1) */ lua_setfield(L, -2, "__index"); /* { __index = _G } (sp -= 1) */ lua_setmetatable(L, -2); /* setmetatable({}, {__index = _G}) (sp -= 1) */ @@ -969,7 +968,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_remove(L, errfunc); /* reset environment */ - magnet_get_global_table(L); /* (sp += 1) */ + lua_pushglobaltable(L); /* (sp += 1) */ magnet_setfenv_mainfn(L, 1); /* (sp -= 1) */ if (0 != ret) {