[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: _ENV vs _G
- From: Coda Highland <chighland@...>
- Date: Mon, 11 Aug 2014 10:37:16 -0700
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