# HG changeset patch # User Kim Alvefur # Date 1410999768 -7200 # Node ID ae798314347cfc22f50762e8de0c089eb4330e73 # Parent d782cbb46c2a359fd9e1d616dc6328f875a0aefa# Parent 060b63a27e9b27bbc6bb37cf9f418706218956c1 Merge 0.10->trunk diff -r d782cbb46c2a -r ae798314347c core/moduleapi.lua --- a/core/moduleapi.lua Tue Sep 16 13:02:21 2014 -0400 +++ b/core/moduleapi.lua Thu Sep 18 02:22:48 2014 +0200 @@ -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"; @@ -19,6 +19,7 @@ local error, setmetatable, type = error, setmetatable, type; local ipairs, pairs, select = ipairs, pairs, select; local tonumber, tostring = tonumber, tostring; +local require = require; local pack = table.pack or function(...) return {n=select("#",...), ...}; end -- table.pack is only in 5.2 local unpack = table.unpack or unpack; -- renamed in 5.2 @@ -386,7 +387,10 @@ 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; +return function (mm) + modulemanager = mm; + return api; +end diff -r d782cbb46c2a -r ae798314347c core/modulemanager.lua --- a/core/modulemanager.lua Tue Sep 16 13:02:21 2014 -0400 +++ b/core/modulemanager.lua Thu Sep 18 02:22:48 2014 +0200 @@ -37,7 +37,7 @@ 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 = { ["*"] = {} }; diff -r d782cbb46c2a -r ae798314347c prosody --- a/prosody Tue Sep 16 13:02:21 2014 -0400 +++ b/prosody Thu Sep 18 02:22:48 2014 +0200 @@ -153,7 +153,12 @@ 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); diff -r d782cbb46c2a -r ae798314347c util-src/encodings.c --- a/util-src/encodings.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/encodings.c Thu Sep 18 02:22:48 2014 +0200 @@ -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[]= @@ -361,35 +365,26 @@ /***************** 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); 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 -r d782cbb46c2a -r ae798314347c util-src/hashes.c --- a/util-src/hashes.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/hashes.c Thu Sep 18 02:22:48 2014 +0200 @@ -27,6 +27,10 @@ #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 @@ -203,9 +207,9 @@ LUALIB_API int luaopen_util_hashes(lua_State *L) { - luaL_register(L, "hashes", Reg); - lua_pushliteral(L, "version"); /** version */ + lua_newtable(L); + luaL_register(L, NULL, Reg); lua_pushliteral(L, "-3.14"); - lua_settable(L,-3); + lua_setfield(L, -2, "version"); return 1; } diff -r d782cbb46c2a -r ae798314347c util-src/net.c --- a/util-src/net.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/net.c Thu Sep 18 02:22:48 2014 +0200 @@ -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[] = { @@ -112,6 +116,7 @@ { NULL, NULL } }; - luaL_register(L, "net", exports); + lua_newtable(L); + luaL_register(L, NULL, exports); return 1; } diff -r d782cbb46c2a -r ae798314347c util-src/pposix.c --- a/util-src/pposix.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/pposix.c Thu Sep 18 02:22:48 2014 +0200 @@ -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 @@ -768,7 +772,8 @@ { 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 -r d782cbb46c2a -r ae798314347c util-src/signal.c --- a/util-src/signal.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/signal.c Thu Sep 18 02:22:48 2014 +0200 @@ -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 @@ -384,13 +388,14 @@ 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, * 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 -r d782cbb46c2a -r ae798314347c util-src/windows.c --- a/util-src/windows.c Tue Sep 16 13:02:21 2014 -0400 +++ b/util-src/windows.c Thu Sep 18 02:22:48 2014 +0200 @@ -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; @@ -81,9 +85,9 @@ }; LUALIB_API int luaopen_util_windows(lua_State *L) { - luaL_register(L, "windows", Reg); - lua_pushliteral(L, "version"); /** version */ + lua_newtable(L); + luaL_register(L, NULL, Reg); lua_pushliteral(L, "-3.14"); - lua_settable(L,-3); + lua_setfield(L, -2, "version"); return 1; } diff -r d782cbb46c2a -r ae798314347c util/array.lua --- a/util/array.lua Tue Sep 16 13:02:21 2014 -0400 +++ b/util/array.lua Thu Sep 18 02:22:48 2014 +0200 @@ -14,6 +14,7 @@ local math_floor = math.floor; local pairs, ipairs = pairs, ipairs; local tostring = tostring; +local type = type; local array = {}; local array_base = {};