[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (work4) now available
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Mon, 2 Aug 2010 18:55:34 +0200
2010/8/2 James Graves <ansible@xnet.com>:
> On Mon, Aug 02, 2010 at 06:30:39AM +0700, GrayFace wrote:
>> 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)
You can use newindex to perform something similar :
local _M = {}
local _ENV = setmetatable({},{__index=_ENV, __newindex=_M})
function foo()
end
return _M