Operators
Lua comes with numerous built-in operators.
Arithmetic operators
Arithmetic operators like +, -,*,/ are applied to numbers. Since numbers are floating point numbers in Lua, divisions are always floating point divisions:
1.0 / 2 -- result 0.5
1 / 2 -- result 0.5, not 0
1 - 3*4 -- result -11
41/10 -- result 4.1
Assignment operator
The assignment operator = overwrites the variable at the left-hand side with the result of the right-hand side operation.
i = 10 - 2 -- result i==8
Operator . .
The .. operator concatenates data to character strings (after converting them to strings).
"At receiver: " .. 10.3 .. " dB"
-- result: "At receiver: 10.3 dB"
Comparison operators
Comparison operators compare values. They always evaluate to true or false.
1 == 1 -- result: `true`
2 == 1 -- result: `false`
2 <= 1 -- result: `false`
2 > 1 -- result: `true`
2 >= 1 -- result: `true`
2 ~= 1 -- inequality, result: `false`
-- etc
Logical operators
Logical operators and, or and not can express logical statements. They operate on boolean values and show the following behavior:
not true -- result: `false`
not false -- result: `true`
false and x -- result: `false` (short-circuit)
true and x -- result: `x`
false or x -- result: `x`
true or x -- result: `true` (short-circuit)
and, or and not can be used with non-boolean values as well. Lua interprets nil as if it was false and all other values as true-equivalent.
not 0 -- result: `false` since 0 is true-ish
not nil -- result: `true` since nil is false-ish