lua-users home
lua-l archive

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


On 02.08.2010 6:21, Quae Quack wrote:
I've always been in favour of localising the global functions you use;
but no, I believe they meant to use
local _ENV = setmetatable({},{__index=_G})
function foo()
end
return _ENV
This would be better written

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


--
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru