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 module. The syntax for modules is:*
module ::= { statement | function }A module may contain statements and function definitions, and may be in a file or in a string inside the host program. When a module is executed, first all its functions and statements are compiled, and the functions added to the global environment; then the statements are executed in sequential order. All modifications a module effects on the global environment persist after its end. Those include modifications to global variables and definitions of new functions*.
Next: 3 Types Up: Reference Manual of the Previous: 1 Introduction