lua-users home
lua-l archive

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


On Mon, Aug 11, 2014 at 10:31 AM, Steven Degutis <sbdegutis@gmail.com> wrote:
> I've also been pretty confused on what _G does specifically.

Instead of trying to respond to the contents of the e-mails, I'll give
a very short explanation.

When a chunk (usually a file, but also anything you've created with
something like loadstring) starts, _G is a reference to _ENV.

(_ENV is the "global scope", and any variable references that can't be
found as local definitions or upvalues are looked up in the _ENV
table. You can explicitly look inside _ENV if you want to grab a
global that was shadowed by a local or upvalue.)

Beyond that, there's absolutely nothing magical about _G. Its purpose
is to be a reference to the original _ENV if you replace it. All of
the remaining commentary is just a description of how non-magical _G
is.

That's literally all there is to it.

/s/ Adam