# HG changeset patch # User Florian Zeitz # Date 1339197501 -7200 # Node ID 776a57ca0d84edc9d5af67dcfbb90139dbe903ba # Parent 85b2689dbcfec071c3721388404f858e73a8eb5e prosody: Define a getfenv() replacement for Lua 5.2 diff -r 85b2689dbcfe -r 776a57ca0d84 prosody --- a/prosody Fri Jun 08 05:04:38 2012 +0200 +++ b/prosody Sat Jun 09 01:18:21 2012 +0200 @@ -145,9 +145,13 @@ -- for neat sandboxing of modules local _realG = _G; local _real_require = require; + if not getfenv then + -- FIXME: This is a hack to replace getfenv() in Lua 5.2 + function getfenv(f) return debug.getupvalue(debug.getinfo(f or 1).func, 1); end + end function require(...) local curr_env = getfenv(2); - local curr_env_mt = getmetatable(getfenv(2)); + local curr_env_mt = getmetatable(curr_env); local _realG_mt = getmetatable(_realG); if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then local old_newindex, old_index;