A single name can denote a global variable or a local variable (or a function’s formal parameter, which is a particular kind of local variable):
Name denotes identifiers, as defined in .
Before the first assignment to a variable, its value is nil.
Square brackets are used to index a table:
The syntax var.Name
is just syntactic sugar for :
All global variables live as fields in ordinary Lua tables, called environment tables or simply environments (see §2.9). Each function has its own reference to an environment, so that all global variables in this function will refer to this environment table. When a function is created, it inherits the environment from the function that created it. To get the environment table of a Lua function, you call . To replace it, you call setfenv
. (You can only manipulate the environment of C functions through the debug library; (see ).)
where _env
is the environment of the running function. (See §2.8 for a complete description of the gettable_event
function. This function is not defined or callable in Lua. Similarly, the _env
variable is not defined in Lua. We use them here only for explanatory purposes.)