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