lua-users home
lua-l archive

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


On Mon, Aug 02, 2010 at 06:30:39AM +0700, GrayFace wrote:

> local _ENV = setmetatable({},{__index=_ENV})
> function foo()
> end
> return _ENV
> 
> Notice _ENV used instead of _G.
> 
> Yet, I think Jim was talking about something like this:
> 
> local _G = _ENV
> local _ENV = {}
> function foo()
>    return _G.print("Hello phlnc8!")
> end
> return _ENV

In the first case using setmetatable(), would it be advisable to
delete the metatable before returning _ENV?  So the code would then
be: 

local _ENV = setmetatable({},{__index=_ENV})
function foo()
end
return setmetatable(_ENV, nil)

Best regards,

James