|
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 ::= {stat [`;´]}
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 §2.5.9).
As such, chunks can define local variables,
receive arguments, and return values.
A chunk may be stored in a file or in a string inside the host program.
When a chunk is executed, first it is pre-compiled into instructions for
a virtual machine,
and then the compiled code is executed
by an interpreter for the virtual machine.
Chunks may also be pre-compiled into binary form;
see program luac for details.
Programs in source and compiled forms are interchangeable;
Lua automatically detects the file type and acts accordingly. |