lua-users home
lua-l archive

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


David Kastrup wrote:
Up to now, the difference is quite too much in the "eyes glaze over"
department for my taste.

I don't like the idea of reusing the _G name; it could lead to confusion because _G and _ENV are quite different beasts. Consider (5.1):

 a = 3
 print(a) --> 3
 print(_G.a) --> 3

 _G = { a = 4 }
 print(a) --> 3  [*]
 print(_G.a) --> 4

[*] with _ENV instead of _G, this would be 4 (if I'm not mistaken).

In short, _G is just a reference to the globals table; changing _G will not change the global table. On the other hand, _ENV is an upvalue containing the current 'globals' table; changing _ENV will change the 'globals'.

(maybe it would be better to use a term such as "non-locals")

  Enrico