Register forum user name Search FAQ

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)


See Also ...

Lua keywords/topics

assignment
break
comments
data types
do
for (generic)
for (numeric)
function
identifiers
if / then / else
keywords
local
logical operators
relational operators
repeat
return
string literals
tables
while

Topics

Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua SQLite (database) interface
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins

(Help topic: lua=precedence)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.