lua-users home
lua-l archive

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

>function func()
>  a=1;
>setfenv(func, setmetatable(g, {__index=_G}))
>What is the correct way to tidy up from here?
>Is it necessary to issue another setfenv() before
>setting g or func to nil? 

Setting g to nil has no effect on func after the setfenv call.
I'm not sure what you mean by tidying up. Perhaps it will be clearer if
you use a local g instead of a global one.

>Is func collectable after setting its value to nil or
>does the setfenv() continue to reference func()?

There are no references from env tables to functions, only the other way around.