Chunks
The unit of execution of Lua is called a chunk. A chunk is simply a sequence of statements, which are executed sequentially. Each statement can be optionally followed by a semicolon:
chunk ::= {statement [`;´]}
There are no empty statements and thus ';;
' is not legal.
Lua handles a chunk as the body of an anonymous function with a variable number of arguments (see Function Calls as Statements). As such, chunks can define local variables, receive arguments, and return values.
A chunk can be stored in a file or in a string inside the host program. To execute a chunk, Lua first pre-compiles the chunk into instructions for a virtual machine, and then it executes the compiled code with an interpreter for the virtual machine. Frequently used code paths will be dynamically compiled into 80x86 machine instructions by the JIT compiler.