Справочное руководство по языку Lua 5.1 :: 2.4.7 - Управляющие конструкции



2.4.7 - Local Declarations

>Local variables may be declared anywhere inside a block. The declaration may include an initial assignment:


stat ::= local namelist ['=' explist1]

If present, an initial assignment has the same semantics of a multiple assignment (see §2.4.3). Otherwise, all variables are initialized with nil.

A chunk is also a block (see §2.4.1), and so local variables can be declared in a chunk outside any explicit block. The scope of such local variables extends until the end of the chunk.

The visibility rules for local variables are explained in §2.6.