lua-users home
lua-l archive

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


2012/5/7 Emeka <emekamicro@gmail.com>:
> A global variable (not a function) that holds the global environment
> (see §2.2). Lua itself does not use this variable; changing its value does
> not affect any environment, nor vice-versa.
>
> The above is still confusing, what is it used for? And why is it there at
> all?
>

>> > However, I have a question, what is _G? And, why is it empty when I try
>> > it on the shell?

In Lua 5.2, _ENV can point to many different tables depending on what
the program is doing. _G is just another name for the original _ENV.
To go back to the original _ENV, you just say _ENV=_G.

It is not empty in the shell, but since it has no numeric keys,
#_G comes out zero.