All statements in Lua are executed in a global environment. This environment, which keeps all global variables and functions, is initialized at the beginning of the embedding program and persists until its end.
The global environment can be manipulated by Lua code or by the embedding program, which can read and write global variables using functions in the library that implements Lua.
Global variables do not need declaration. Any variable is assumed to be global unless explicitly declared local (see local declarations, Section 4.4.5). Before the first assignment, the value of a global variable is nil.
The unit of execution of Lua is called a chunk. The syntax for chunks is:*
chunk ::= { statement | function }A chunk may contain statements and function definitions, and may be in a file or in a string inside the host program. When a chunk is executed, first all its functions and statements are compiled, then the statements are executed in sequential order. All modifications a chunk effects on the global environment persist after its end. Those include modifications to global variables and definitions of new functions*.