How can I recreate the functionality of setfenv in Lua 5.2? I\'m having some trouble understanding exactly how you are supposed to use the new _ENV
setfenv
_ENV
It's a bit expensive, but if it's that important to you...
Why not use string.dump, and re-load the function into the right environment?
function setfenv(f, env) return load(string.dump(f), nil, nil, env) end function foo() herp(derp) end setfenv(foo, {herp = print, derp = "Hello, world!"})()