|
I rewrite setfenv as follow :
local function setfenv (level, M)
level = level + 1
local func = debug.getinfo(level, 'f').func
local up = 1
while true do
local name = debug.getupvalue(func, up)
if name == '_ENV' then
debug.setupvalue(func, up, M)
return
end
if name == nil then
break
end
up = up + 1
end
_G.setfenv(level, M) -- Lua 5.1
end
François