lua-users home
lua-l archive

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


Is it possible to use setfenv recursively?  When I call setfenv, it attaches to the function, but it seems like it should more naturally attach to the function's call. 

I have a little wrapper function to protect my environment:

function protectedEnv(func)
    local env = {}
    setmetatable(env, { __index = _G })
    setfenv(func, env)
    return func
end

...

myFunc = protectedEnv(
    function()
        -- If I call myFunc inside here, my environments start colliding.
    end)
   
...

myFunc()