lua-users home
lua-l archive

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


PA wrote:
local aFunction = function( aName )
        return ( "%s! Yes, we can!" ):format( aName )
end
local aFunctionCopy = loadstring( string.dump( aFunction ) )
This trick won't help you with cfunctions. And require is a cfunction.
Why called function doesn't inherit the environment of caller?

--pseudocode
function __call(callee, caller)
 if not callee.env.wasChangedBySetfenv then
   local env = callee.env
   callee.env = caller.env
   __real_call(callee)
   callee.env = env
 else
   __real_call(callee)
 end
end