[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (work4) now available
- From: Nevin Flanagan <Alestane@...>
- Date: Tue, 3 Aug 2010 16:14:04 -0400
On Aug 3, 2010, at 4:01 AM, Quae Quack wrote:
> Can this not be done like so?:
> local MOD = {}
> local _ENV = setmetatable({},{__index=function(t,k) return MOD[k] or
> _G[K] end , __newindex=function(t,k,v) MOD[k] = v end })
> return MOD
Isn't this functionally equivalent (or at least very close) to
local MOD = {}
_ENV = setmetatable(MOD, {__index=_G})
-- stuff
return MOD
?
The other method I've seen is to use a function, but cache anything accessed:
local _G = _ENV
_ENV = setmetatable({}, {__index = function(t, k) t[k] = _G[k]; return t[k] end})
--stuff
return _ENV
- References:
- Re: [ANN] Lua 5.2.0 (work4) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.0 (work4) now available, Florian Weimer
- Re: [ANN] Lua 5.2.0 (work4) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.2.0 (work4) now available, phlnc8
- Re: [ANN] Lua 5.2.0 (work4) now available, Jim Whitehead II
- Re: [ANN] Lua 5.2.0 (work4) now available, phlnc8
- Re: [ANN] Lua 5.2.0 (work4) now available, Quae Quack
- Re: [ANN] Lua 5.2.0 (work4) now available, GrayFace
- Re: [ANN] Lua 5.2.0 (work4) now available, James Graves
- Re: [ANN] Lua 5.2.0 (work4) now available, Jerome Vuarand
- Re: [ANN] Lua 5.2.0 (work4) now available, David Manura
- Re: [ANN] Lua 5.2.0 (work4) now available, Quae Quack