Diff

core/configmanager.lua @ 5021:85b2689dbcfe

Eliminate direct setfenv usage
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 08 Jun 2012 05:04:38 +0200
parent 4530:40905e7bf680
child 5124:a4a74a0e9b9c
line wrap: on
line diff
--- a/core/configmanager.lua	Thu Jun 07 23:27:26 2012 +0200
+++ b/core/configmanager.lua	Fri Jun 08 05:04:38 2012 +0200
@@ -13,6 +13,7 @@
 
 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 @@
 
 -- 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 @@
 			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