equal
deleted
inserted
replaced
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); |