Expressions
-
Arithmetic Operations
-
Relational Operations
-
Logical Operations
-
Concatenation
-
Length
-
Precedence
Arithmetic operations
| a + b | add a and b |
| a - b | subtract b from a |
| a * b | multiply a and b |
| a / b | divide a by b |
| a % b | modulo = a - math.floor(a/b)*b |
| a \^ b | raise a to the b power; b can be any number |
| -a | negate a |
Relational operations
| a == b | a is equal to b |
| a ~= b | a is not equal to b |
| a < b | a is less than b |
| a > b | a is greater than b |
| a <= b | a is less than or equal to b |
| a >= b | a is greater than or equal to b |
Logical operations
| a and b | if a is false or nil then return a else return b |
| a or b | if a is not false and not nil then return a else return b |
| not a | if a is not false or nil return false else return true |
| a or b | can be used to provide a default value b if a is uninitialized (nil). This is useful for optional parameters in functions. |
| a and b or c | can be used to chose non-nil b or c based on the condition a. If a is true, then a and b returns b, and b or c returns b. If a is false, then a and b returns false and false or c returns c. This is equivalent to a ? b : c in the C programming language. |
Concatenation
Length
Precedence
a + b * c, * has higher precedence than +, so the expression is evaluated as a + (b * c).
| highest | \^ |
| - | not # - (unary) |
| - |
|
| - |
|
| - | .. |
| - | = ~= < > <= >= |
| - | and |
| lowest | or |