|
Well I wouldn't propose it as the default behaviour at all, but it would be nice to be able to create 'environment-less' functions in addition to Lua's functions with bound environments. I didn't know about debug.sethook, but looking at it now, it seems that it would affect ALL function calls (and I suppose will be expensive too). perhaps a wrapper function: function envwrap(f) setfenv(f, getfenv(1)) return f() end or more correctly function envwrap(f) local e = getfenv(f) setfenv(f, getfenv(1)) args = {f()} setfenv(f, e) return unpack(args) end and in use: fsub = function() print("fsub", getfenv(0), getfenv(1)) b = 1 end fmain = function() print("fmain", getfenv(0), getfenv(1)) a = 1 envwrap(fsub()) end But I feel like I'm doing a lot of expensive workaround, where a simpler 'environment-less' function would suffice. On Mar 24, 2007, at 4:00 PM, Tomas Guisasola Gorham wrote:
Grrr Waaa www.grahamwakefield.net |