lua-users home
lua-l archive

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


On Tue, Aug 3, 2010 at 4:01 AM, Quae Quack <quae@daurnimator.com> 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

Yes, although this imposes an overhead (function call) on accessing
all globals in _G, and we ask whether it's worth it over just doing
"local M = {}; function M.foo() M.bar() end; function M.bar();
print'!' end; return M".