prosody
changeset 6419 9af742bb45b2
parent 6067 dab7ad6fa23c
child 6473 67501b5576d3
equal deleted inserted replaced
6418:010b141e91ed 6419:9af742bb45b2
   151 	-- for neat sandboxing of modules
   151 	-- for neat sandboxing of modules
   152 	local _realG = _G;
   152 	local _realG = _G;
   153 	local _real_require = require;
   153 	local _real_require = require;
   154 	if not getfenv then
   154 	if not getfenv then
   155 		-- FIXME: This is a hack to replace getfenv() in Lua 5.2
   155 		-- FIXME: This is a hack to replace getfenv() in Lua 5.2
   156 		function getfenv(f) return debug.getupvalue(debug.getinfo(f or 1).func, 1); end
   156 		function getfenv(f)
       
   157 			local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
       
   158 			if name == "_ENV" then
       
   159 				return env;
       
   160 			end
       
   161 		end
   157 	end
   162 	end
   158 	function require(...)
   163 	function require(...)
   159 		local curr_env = getfenv(2);
   164 		local curr_env = getfenv(2);
   160 		local curr_env_mt = getmetatable(curr_env);
   165 		local curr_env_mt = getmetatable(curr_env);
   161 		local _realG_mt = getmetatable(_realG);
   166 		local _realG_mt = getmetatable(_realG);