aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2012-06-08 05:04:38 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2012-06-08 05:04:38 +0200
commitd49b9bc2abb50b22ae3d6739d96423e9dadfeda8 (patch)
tree28c1bcbab960b28cc27f30e8ab0c04e30f11da2d /core/modulemanager.lua
parent217e6d011c8d8ae2c44034fc9138925d77c3c10b (diff)
downloadprosody-d49b9bc2abb50b22ae3d6739d96423e9dadfeda8.tar.gz
prosody-d49b9bc2abb50b22ae3d6739d96423e9dadfeda8.zip
Eliminate direct setfenv usage
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua19
1 files changed, 10 insertions, 9 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 488319c3..9c5e4a4a 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -18,7 +18,7 @@ local hosts = hosts;
local prosody = prosody;
local pcall, xpcall = pcall, xpcall;
-local setmetatable, rawget, setfenv = setmetatable, rawget, setfenv;
+local setmetatable, rawget = setmetatable, rawget;
local pairs, type, tostring = pairs, type, tostring;
local debug_traceback = debug.traceback;
@@ -152,22 +152,23 @@ local function do_load_module(host, module_name)
end
- local mod, err = pluginloader.load_code(module_name);
- if not mod then
- log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil");
- return nil, err;
- end
local _log = logger.init(host..":"..module_name);
- local api_instance = setmetatable({ name = module_name, host = host, path = err,
+ local api_instance = setmetatable({ name = module_name, host = host,
_log = _log, log = function (self, ...) return _log(...); end, event_handlers = new_multitable() }
, { __index = api });
local pluginenv = setmetatable({ module = api_instance }, { __index = _G });
api_instance.environment = pluginenv;
- setfenv(mod, pluginenv);
-
+ local mod, err = pluginloader.load_code(module_name, nil, pluginenv);
+ if not mod then
+ log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil");
+ return nil, err;
+ end
+
+ api_instance.path = err;
+
modulemap[host][module_name] = pluginenv;
local ok, err = pcall(mod);
if ok then