Precedence

Precedence in detail

by Halalaluyafail3

Author Avatar

Precedence is how the operators are evaluted, so something like 3+5*2 ends up as 13, and not 16.

For control over precedence, use parenthesis '(' and ')' to force operations to happen in a specific order.

Indexing ('a.b' or 'a[b]'), function calls ('a(...)'), and method calls ('a:b(...)') always have a higher precedence than the operators.

In lua 5.1 this is the precedence. (from higher to lower priority)

(binary)^



(unary)not      (unary)#      (unary)-



(binary)*      (binary)/      (binary)%



(binary)+      (binary)-



(binary)..



(binary)==      (binary)~=      (binary)<      (binary)>
(binary)<=      (binary)>=



(binary)and



(binary)or

The concatenation operator ('..') and the exponentation operator ('^') are right associative, while everything else is left associative.

i.e

x..y..z is equivalent to x..(y..z)

and

x+y+z is equivalent to (x+y)+z

View in-game to comment, award, and more!