-- `false` and `nil` evals are falsy in lua.-- all other values are truthye1 and e2 --> e1 if e1 is falsy else e2e1 or e2 --> e1 if e1 is truthy else e2not e --> true if e1 is falsy else false-- Both `and` and `or` are short-circuitx = x or v -- equivalent toif not x then x = v enda and b or c --> equivalent to a ? b : c in other language
Numbers
Numerals
type(3) --> numbertype(3.0) --> numbermath.type(3) --> integermath.type(3.0) --> float0xff --> 2550x0.2 --> 0.1250x1p-1 --> 0.5 same as 1 * (2 ^ -1)0xa.bp2 --> 42.75 same as a.b * (2 ^ 2)
Arithmetic Operators
e1 + e2 --> math.type is integer if both e1 and e2 are integers else floate1 - e2 e1 * e2e1 / e2 --> always type floate1 // e2 --> floor divition. always rounds the quotient towards minus infinity -- Type is integer if both e1 and e2 are integers else floate1 % e2 --> modulo operator. equiv to `e1 - ((e1 // e2) * e2)`e1 ^ e2 --> exponential. always type float
Relational Operators
e1 < e2e1 > e2e1 <= e2e1 >= e2e1 == e2e1 ~= e2
Strings
-- string in lua is immutablea = "one string"b = string.gsub(a, "one", "another") --> "another string"#a --> 10. length of string#"hello" --> 5"Hello " .. "World" --> "Hello World" string concatenation"result is " .. 3 --> "result is 3"