lua-users home
lua-l archive

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


2014-03-31 15:15 GMT+02:00 Thomas Jericke <tjericke@indel.ch>:

> http://lua-users.org/lists/lua-l/2002-04/msg00177.html
>
> See, the Lua team was there already. For me it's a petty that they dropped
> those ideas. I have myself a metatable on the globals to support this stuff.
> But a general solution to such a basic problem would be nice.

Some history:

1993 Lua released.
1995 Lua 2.1 provides fallbacks.
1997 Lua 3.0 replaces fallbacks by tag methods.
2003 Lua 5.0 replaces tag methods by metamethods.
2011 Lua 5.2 stores globals in _ENV.

I would not say that the Lua team dropped the ideas. On the contrary,
starting just the year after that post, they present a general solution so
basic that user control over globals is merely one of the many things
it solves.

Honestly, I can't understand the squeamishness some people have
about _ENV. You are allowed to treat it like any other table, including
equipping it with metamethods, so do it. That is not dodgy programming,
it is exploiting features the designers meant to make available to you.

strict.lua is not supposed to be a tool everybody should use, it is
a sample module demonstrating just one powerful thing that
metatables allow you to do. This is how Teacher paints a cat,
now you go and paint a leopard for me.

And _G. There's nothing sacred about _G. It's merely another name
for the table containing the lowest-level _ENV. The only claim made
for _G in the Lua manual is that nothing in Lua and its libraries ever
changes _G. That's not because _G is a holy cow, it is because
_G is good for nothing besides stopping the first _ENV from being
garbage-collected. _G is not being worshipped, it is being ignored.