aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/configmanager.lua9
-rw-r--r--core/moduleapi.lua7
-rw-r--r--core/modulemanager.lua19
-rw-r--r--core/rostermanager.lua2
4 files changed, 18 insertions, 19 deletions
diff --git a/core/configmanager.lua b/core/configmanager.lua
index e2253171..8fea3be5 100644
--- a/core/configmanager.lua
+++ b/core/configmanager.lua
@@ -13,6 +13,7 @@ local format, math_max = string.format, math.max;
local fire_event = prosody and prosody.events.fire_event or function () end;
+local envload = require"util.envload".envload;
local lfs = require "lfs";
local path_sep = package.config:sub(1,1);
@@ -164,8 +165,8 @@ end
-- Built-in Lua parser
do
- local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable;
- local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring;
+ local pcall, setmetatable = _G.pcall, _G.setmetatable;
+ local rawget, tostring = _G.rawget, _G.tostring;
parsers.lua = {};
function parsers.lua.load(data, config_file, config)
local env;
@@ -263,14 +264,12 @@ do
return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file));
end
- local chunk, err = loadstring(data, "@"..config_file);
+ local chunk, err = envload(data, "@"..config_file, env);
if not chunk then
return nil, err;
end
- setfenv(chunk, env);
-
local ok, err = pcall(chunk);
if not ok then
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 572dc179..54077826 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -15,7 +15,7 @@ local pluginloader = require "util.pluginloader";
local timer = require "util.timer";
local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat;
-local error, setmetatable, setfenv, type = error, setmetatable, setfenv, type;
+local error, setmetatable, type = error, setmetatable, type;
local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack;
local tonumber, tostring = tonumber, tostring;
@@ -97,12 +97,11 @@ end
api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9
function api:require(lib)
- local f, n = pluginloader.load_code(self.name, lib..".lib.lua");
+ local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment);
if not f then
- f, n = pluginloader.load_code(lib, lib..".lib.lua");
+ f, n = pluginloader.load_code(lib, lib..".lib.lua", self.environment);
end
if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message
- setfenv(f, self.environment);
return f();
end
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
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index 524b61be..ac4f4e3d 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -13,7 +13,7 @@ local log = require "util.logger".init("rostermanager");
local setmetatable = setmetatable;
local format = string.format;
-local loadfile, setfenv, pcall = loadfile, setfenv, pcall;
+local pcall = pcall;
local pairs, ipairs = pairs, ipairs;
local tostring = tostring;