lua-users home
lua-l archive

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


	Hi Enrico

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 fact, it will throw an error, because print (or _ENV.print)
does not exist :-)

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'.
	Not exactly:

_G.print = nil -- equivalent to _ENV.print = nil

	Regards,
		Tomás