Browse Source

[mod_magnet] define lua_pushglobaltable (for lua5.1) and use it (fixes #2719)

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3106 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Stefan Bühler 6 years ago
parent
commit
82ee3fb2f8
  1. 1
      NEWS
  2. 13
      src/mod_magnet.c

1
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)

13
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) {

Loading…
Cancel
Save