From c57e98cd7debd8d8ea46159cbbf2eb7597544d4c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 16 Sep 2014 21:56:18 +0200 Subject: util-src/*.c: Don't create globals when loaded --- util-src/encodings.c | 7 +------ util-src/hashes.c | 3 ++- util-src/net.c | 3 ++- util-src/pposix.c | 3 ++- util-src/signal.c | 3 ++- util-src/windows.c | 3 ++- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/util-src/encodings.c b/util-src/encodings.c index b9b6160a..3a074949 100644 --- a/util-src/encodings.c +++ b/util-src/encodings.c @@ -361,17 +361,12 @@ static const luaL_Reg Reg_idna[] = /***************** end *****************/ -static const luaL_Reg Reg[] = -{ - { NULL, NULL } -}; - LUALIB_API int luaopen_util_encodings(lua_State *L) { #ifdef USE_STRINGPREP_ICU init_icu(); #endif - luaL_register(L, "encodings", Reg); + lua_newtable(L); lua_pushliteral(L, "base64"); lua_newtable(L); diff --git a/util-src/hashes.c b/util-src/hashes.c index 33041e83..7ca00867 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -203,7 +203,8 @@ static const luaL_Reg Reg[] = LUALIB_API int luaopen_util_hashes(lua_State *L) { - luaL_register(L, "hashes", Reg); + lua_newtable(L); + luaL_register(L, NULL, Reg); lua_pushliteral(L, "version"); /** version */ lua_pushliteral(L, "-3.14"); lua_settable(L,-3); diff --git a/util-src/net.c b/util-src/net.c index e307c628..84d7e84e 100644 --- a/util-src/net.c +++ b/util-src/net.c @@ -112,6 +112,7 @@ int luaopen_util_net(lua_State* L) { NULL, NULL } }; - luaL_register(L, "net", exports); + lua_newtable(L); + luaL_register(L, NULL, exports); return 1; } diff --git a/util-src/pposix.c b/util-src/pposix.c index 9b3e97eb..62bd0339 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -768,7 +768,8 @@ int luaopen_util_pposix(lua_State *L) { NULL, NULL } }; - luaL_register(L, "pposix", exports); + lua_newtable(L); + luaL_register(L, NULL, exports); lua_pushliteral(L, "pposix"); lua_setfield(L, -2, "_NAME"); diff --git a/util-src/signal.c b/util-src/signal.c index 961d2d3e..405689f5 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -384,7 +384,8 @@ int luaopen_util_signal(lua_State *L) int i = 0; /* add the library */ - luaL_register(L, "signal", lsignal_lib); + lua_newtable(L); + luaL_register(L, NULL, lsignal_lib); /* push lua_signals table into the registry */ /* put the signals inside the library table too, diff --git a/util-src/windows.c b/util-src/windows.c index 3d14ca95..9b79c662 100644 --- a/util-src/windows.c +++ b/util-src/windows.c @@ -81,7 +81,8 @@ static const luaL_Reg Reg[] = }; LUALIB_API int luaopen_util_windows(lua_State *L) { - luaL_register(L, "windows", Reg); + lua_newtable(L); + luaL_register(L, NULL, Reg); lua_pushliteral(L, "version"); /** version */ lua_pushliteral(L, "-3.14"); lua_settable(L,-3); -- cgit v1.2.3 From 4f6f0fe48047cf1832061f52aa96b9df5d9460fa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 02:23:17 +0200 Subject: util-src/*.c: Use the more concise lua_setfield --- util-src/encodings.c | 12 ++++-------- util-src/hashes.c | 3 +-- util-src/signal.c | 2 +- util-src/windows.c | 3 +-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/util-src/encodings.c b/util-src/encodings.c index 3a074949..fb838551 100644 --- a/util-src/encodings.c +++ b/util-src/encodings.c @@ -368,23 +368,19 @@ LUALIB_API int luaopen_util_encodings(lua_State *L) #endif lua_newtable(L); - lua_pushliteral(L, "base64"); lua_newtable(L); luaL_register(L, NULL, Reg_base64); - lua_settable(L,-3); + lua_setfield(L, -2, "base64"); - lua_pushliteral(L, "stringprep"); lua_newtable(L); luaL_register(L, NULL, Reg_stringprep); - lua_settable(L,-3); + lua_setfield(L, -2, "stringprep"); - lua_pushliteral(L, "idna"); lua_newtable(L); luaL_register(L, NULL, Reg_idna); - lua_settable(L,-3); + lua_setfield(L, -2, "idna"); - lua_pushliteral(L, "version"); /** version */ lua_pushliteral(L, "-3.14"); - lua_settable(L,-3); + lua_setfield(L, -2, "version"); return 1; } diff --git a/util-src/hashes.c b/util-src/hashes.c index 7ca00867..39ab5180 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -205,8 +205,7 @@ LUALIB_API int luaopen_util_hashes(lua_State *L) { lua_newtable(L); luaL_register(L, NULL, Reg); - lua_pushliteral(L, "version"); /** version */ lua_pushliteral(L, "-3.14"); - lua_settable(L,-3); + lua_setfield(L, -2, "version"); return 1; } diff --git a/util-src/signal.c b/util-src/signal.c index 405689f5..3d0a8a50 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -391,7 +391,7 @@ int luaopen_util_signal(lua_State *L) /* put the signals inside the library table too, * they are only a reference */ lua_pushstring(L, LUA_SIGNAL); - lua_createtable(L, 0, 0); + lua_newtable(L); while (lua_signals[i].name != NULL) { diff --git a/util-src/windows.c b/util-src/windows.c index 9b79c662..a209539f 100644 --- a/util-src/windows.c +++ b/util-src/windows.c @@ -83,8 +83,7 @@ static const luaL_Reg Reg[] = LUALIB_API int luaopen_util_windows(lua_State *L) { lua_newtable(L); luaL_register(L, NULL, Reg); - lua_pushliteral(L, "version"); /** version */ lua_pushliteral(L, "-3.14"); - lua_settable(L,-3); + lua_setfield(L, -2, "version"); return 1; } -- cgit v1.2.3 From 8affcc3ff7d35ca73fe748418046bec386496cd2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 14:30:29 +0200 Subject: util-src/*.c: Add macro for compiling with Lua 5.2 --- util-src/encodings.c | 4 ++++ util-src/hashes.c | 4 ++++ util-src/net.c | 4 ++++ util-src/pposix.c | 4 ++++ util-src/signal.c | 4 ++++ util-src/windows.c | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/util-src/encodings.c b/util-src/encodings.c index fb838551..2d5d49d4 100644 --- a/util-src/encodings.c +++ b/util-src/encodings.c @@ -20,6 +20,10 @@ #include "lua.h" #include "lauxlib.h" +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + /***************** BASE64 *****************/ static const char code[]= diff --git a/util-src/hashes.c b/util-src/hashes.c index 39ab5180..459f75ac 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -27,6 +27,10 @@ typedef unsigned __int32 uint32_t; #include #include +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + #define HMAC_IPAD 0x36363636 #define HMAC_OPAD 0x5c5c5c5c diff --git a/util-src/net.c b/util-src/net.c index 84d7e84e..9e57854c 100644 --- a/util-src/net.c +++ b/util-src/net.c @@ -26,6 +26,10 @@ #include #include +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + /* Enumerate all locally configured IP addresses */ const char * const type_strings[] = { diff --git a/util-src/pposix.c b/util-src/pposix.c index 62bd0339..49e80f71 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -35,6 +35,10 @@ #include "lualib.h" #include "lauxlib.h" +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + #include #if defined(__linux__) && defined(_GNU_SOURCE) #include diff --git a/util-src/signal.c b/util-src/signal.c index 3d0a8a50..63d65570 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -32,6 +32,10 @@ #include "lua.h" #include "lauxlib.h" +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + #ifndef lsig #define lsig diff --git a/util-src/windows.c b/util-src/windows.c index a209539f..37f850e3 100644 --- a/util-src/windows.c +++ b/util-src/windows.c @@ -19,6 +19,10 @@ #include "lua.h" #include "lauxlib.h" +#if (LUA_VERSION_NUM == 502) +#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0) +#endif + static int Lget_nameservers(lua_State *L) { char stack_buffer[1024]; // stack allocated buffer IP4_ARRAY* ips = (IP4_ARRAY*) stack_buffer; -- cgit v1.2.3 From a36064641e6e86cbec49d67c615c6ba60cea4f4a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 14:47:52 +0200 Subject: core.moduleapi: Use require instead of global to get storagemanager in module:open_store() --- core/moduleapi.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 8b477140..887ba858 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -19,6 +19,7 @@ local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; local tonumber, tostring = tonumber, tostring; +local require = require; local prosody = prosody; local hosts = prosody.hosts; @@ -366,7 +367,7 @@ function api:load_resource(path, mode) end function api:open_store(name, type) - return storagemanager.open(self.host, name or self.name, type); + return require"core.storagemanager".open(self.host, name or self.name, type); end return api; -- cgit v1.2.3 From 93a297bc8ffd909ff006d664e1e824d8a9307cba Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 14:48:49 +0200 Subject: core.modulemanager, core.moduleapi: Hack around dependency loop --- core/moduleapi.lua | 7 +++++-- core/modulemanager.lua | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 887ba858..e5f86b37 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -7,7 +7,7 @@ -- local config = require "core.configmanager"; -local modulemanager = require "modulemanager"; -- This is necessary to avoid require loops +local modulemanager; -- This gets set from modulemanager local array = require "util.array"; local set = require "util.set"; local logger = require "util.logger"; @@ -370,4 +370,7 @@ function api:open_store(name, type) return require"core.storagemanager".open(self.host, name or self.name, type); end -return api; +return function (mm) + modulemanager = mm; + return api; +end diff --git a/core/modulemanager.lua b/core/modulemanager.lua index db4c6bd0..198e208a 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -37,7 +37,7 @@ local _G = _G; module "modulemanager" -local api = _G.require "core.moduleapi"; -- Module API container +local api = _G.require "core.moduleapi"(_M); -- Module API container -- [host] = { [module] = module_env } local modulemap = { ["*"] = {} }; -- cgit v1.2.3 From cd0acc10f7e3c4032367229c329cb131d739d0b0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 14:50:00 +0200 Subject: prosody: Fix getfenv replacement for Lua 5.2 --- prosody | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prosody b/prosody index 8fcee8e8..aab803c5 100755 --- a/prosody +++ b/prosody @@ -153,7 +153,12 @@ function sandbox_require() local _real_require = require; if not getfenv then -- FIXME: This is a hack to replace getfenv() in Lua 5.2 - function getfenv(f) return debug.getupvalue(debug.getinfo(f or 1).func, 1); end + function getfenv(f) + local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1); + if name == "_ENV" then + return env; + end + end end function require(...) local curr_env = getfenv(2); -- cgit v1.2.3 From e9fa1d1db3a14e8b0d989c3c3e983521034ad38c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Sep 2014 14:50:44 +0200 Subject: util.array: Add type() local --- util/array.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/array.lua b/util/array.lua index 6f2abe04..b10396b1 100644 --- a/util/array.lua +++ b/util/array.lua @@ -14,6 +14,7 @@ local math_random = math.random; local math_floor = math.floor; local pairs, ipairs = pairs, ipairs; local tostring = tostring; +local type = type; local array = {}; local array_base = {}; -- cgit v1.2.3