[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (work4) now available
- From: James Graves <ansible@...>
- Date: Mon, 2 Aug 2010 11:50:32 -0500
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