lua-users home
lua-l archive

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


Which can simply be circumvented if it wouldn't be there:

local _G = _ENV
local _ENV = setmetatable({}, {__index=_ENV})

function print(...)
    _G.print("my print:", ...)
end

I agree with Dirk, _G ought to be deprecated.


On Tue, Aug 12, 2014 at 12:51 PM, Tom N Harris <telliamed@whoopdedo.org> wrote:
On Tuesday, August 12, 2014 09:16:59 AM Dirk Laurie wrote:
> 2014-08-12 8:51 GMT+02:00 Mason Mackaman <masondeanm@aol.com>:
> > Also, so far it seems like _G is the equivalent Lua 5.2’s appendix.
>
> Maybe, for the sake of conceptual integrity, it could be deprecated
> in Lua 5.3.

I think it still has a place.

    local _ENV = setmetatable({}, {__index=_ENV})

    function print(...)
      _G.print("my print:", ...)
    end

There are three general scopes that most sensible programs will concern
themselves with: local, file (or module or class), and global. The first has
the `local' keyword, the second has the _ENV upvalue, and the last has _G.

--
tom <telliamed@whoopdedo.org>