|
Am 09.04.2014 06:13 schröbte Milind Gupta:`_ENV` is an upvalue not a global. So it isn't in the globals table referenced by `_ENV` or `_G` (which really is `_ENV._G`).
I did the following:
print(_G)table: 00C31B98
print(_ENV)table: 00C31B98
print(_G._G)table: 00C31B98
print(_ENV._G)table: 00C31B98
print(_ENV._ENV)nil
print(_G._ENV)nil
No. The rule is simple. When you access a variable `x` you get the innermost local or upvalue with that name in scope, or as a last resort the global variable `_ENV.x` if there is none in scope.
when I do print(_ENV) doesn't it access the variable _ENV._ENV? but
printing _ENV._ENV is nil. So does it mean when I access any other variable
aexcept _ENV it is accessed as _ENV.var?
Sure it can:
So this means that a running code cannot change its own environment as it
could do in Lua 5.1.
_ENV = {}
Milind
Philipp