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
commit40ea2230d1d494c55d8a2b22e111c4bd29074974 (patch)
tree28c1bcbab960b28cc27f30e8ab0c04e30f11da2d /core/modulemanager.lua
parentad7ee8604f2811d3ca3e5adb5faa8c095f4d5999 (diff)
downloadprosody-40ea2230d1d494c55d8a2b22e111c4bd29074974.tar.gz
prosody-40ea2230d1d494c55d8a2b22e111c4bd29074974.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