precedence

Operator precedence specifies which operations are done first (for example, multiply before add).

You can use parentheses to change the precedence of an expression.

From highest to lowest the precedence is:

^
not #   - (unary)
*   /   %
+   -
..
<   >   <=  >=  ~=  ==
and
or
The # operator is the "length" operator which can be applied to things like strings and tables (eg. #"nick" is 4).

All binary operators are left-associative, except for "^" (exponentiation) and ".." (concatenation) which are right-associative.

What this means is that for left-associative operators at the same level (eg. + and -) they are grouped from left to right. Thus:
a - b + c
is the same as:
(a - b) + c
So for example:
3 - 1 + 5  --> 7 (not -3) 
However for concatenation:
a .. b .. c
is the same as:
a .. (b .. c)
And for exponentiation:
a^b^c
is the same as:
a^(b^c)
For example:
print (4^3^2)  --> 262144 (not 4096)

Lua keyword/topics

Topics