lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Solved the issue with
setfenv = setfenv or function(f, t)
   f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
   local name
   local up = 0
   repeat
       up = up + 1
       name = debug.getupvalue(f, up)
   until name == '_ENV' or name == nil
   if name then

debug.upvaluejoin(f, up, function() return name end, 1) -- use unique upvalue

       debug.setupvalue(f, up, t)
   end
end

getfenv = getfenv or function(f)
   f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
   local name, val
   local up = 0
   repeat
       up = up + 1
       name, val = debug.getupvalue(f, up)
   until name == '_ENV' or name == nil
   return val
end

found in http://lua-users.org/lists/lua-l/2010-06/msg00313.html

But I keep thinking that may be there is a better way to do this task in lua52

Best
victor