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.

Bitwise Operators
  • References/Lua/Lua/Language/Expressions

3.4.2 – Bitwise Operators Lua supports the following bitwise operators: &: bitwise AND |: bitwise OR ~:

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
Control Structures
  • References/Lua/Lua/Language/Statements

3.3.4 – Control Structures The control structures if, while, and repeat have the usual meaning and familiar syntax: stat ::=

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

3.4.6 – Concatenation The string concatenation operator in Lua is denoted by two dots ('..'). If both operands are strings or numbers, then they are converted to strings according

2025-01-10 15:47:30
Function Calls as Statements
  • References/Lua/Lua/Language/Statements

3.3.6 – Function Calls as Statements To allow possible side-effects, function calls can be executed as statements: stat ::= functioncall

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

3.3.5 – For Statement The for statement has two forms: one numerical and one generic. The numerical for loop repeats a block of code while a control variable runs through

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

3.4.10 – Function Calls A function call in Lua has the following syntax: functioncall ::= prefixexp args In a function call, first prefixexp

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

3.3.1 – Blocks A block is a list of statements, which are executed sequentially: block ::= {stat} Lua has empty statements that

2025-01-10 15:47:30