3 – The Language

This section describes the lexis, the syntax, and the semantics of Lua. In other words, this section describes which tokens are valid, how they can be combined, and what their combinations mean.

Language constructs will be explained using the usual extended BNF notation, in which {a} means 0 or more a's, and [a] means an optional a. Non-terminals are shown like non-terminal, keywords are shown like kword, and other terminal symbols are shown like ‘=’. The complete syntax of Lua can be found in §9 at the end of this manual.

Local Declarations
  • References/Lua/Lua/Language/Statements

3.3.7 – Local Declarations Local variables can be declared anywhere inside a block. The declaration can include an initial assignment: stat ::= local

2025-01-10 15:47:30
Assignment
  • References/Lua/Lua/Language/Statements

3.3.3 – Assignment Lua allows multiple assignments. Therefore, the syntax for assignment defines a list of variables on the left side and a list of expressions on the right side. The elements

2025-01-10 15:47:30
Arithmetic Operators
  • References/Lua/Lua/Language/Expressions

3.4.1 – Arithmetic Operators Lua supports the following arithmetic operators: +: addition -: subtraction *:

2025-01-10 15:47:30
Table Constructors
  • References/Lua/Lua/Language/Expressions

3.4.9 – Table Constructors Table constructors are expressions that create tables. Every time a constructor is evaluated, a new table is created. A constructor can be used to create an empty

2025-01-10 15:47:30
Chunks
  • References/Lua/Lua/Language/Statements

3.3.2 – Chunks The unit of compilation of Lua is called a chunk. Syntactically, a chunk is simply a block: chunk ::= block Lua

2025-01-10 15:47:30
Precedence
  • References/Lua/Lua/Language/Expressions

3.4.8 – Precedence Operator precedence in Lua follows the table below, from lower to higher priority: or and < > <= >=

2025-01-10 15:47:30
Coercions and Conversions
  • References/Lua/Lua/Language/Expressions

3.4.3 – Coercions and Conversions Lua provides some automatic conversions between some types and representations at run time. Bitwise operators always convert float operands to integers. Exponentiation

2025-01-10 15:47:30
Function Definitions
  • References/Lua/Lua/Language/Expressions

3.4.11 – Function Definitions The syntax for function definition is functiondef ::= function funcbody funcbody ::= ‘(’ [parlist] ‘)’ block end

2025-01-10 15:47:30
The Length Operator
  • References/Lua/Lua/Language/Expressions

3.4.7 – The Length Operator The length operator is denoted by the unary prefix operator #. The length of a string is its number of bytes (that is, the usual meaning of

2025-01-10 15:47:30
Relational Operators
  • References/Lua/Lua/Language/Expressions

3.4.4 – Relational Operators Lua supports the following relational operators: ==: equality ~=: inequality <:

2025-01-10 15:47:30