Comments -- Single line comment --[[ A multi-line comment ]] Types type(nil) --> nil type(true) --> boolean type(10.4*3) --> number type("Hello World") --> string type(is.stdin) --> userdata (C FFI) type(print) --> function type({}) --> table Booleans -- `false` and `nil` evals are falsy in lua. -- all other values are truthy e1 and e2 --> e1 if e1 is falsy else e2 e1 or e2 --> e1 if e1 is truthy else e2 not e --> true if e1 is falsy else false -- Both `and` and `or` are short-circuit x = x or v -- equivalent to if not x then x = v end a and b or c --> equivalent to a ? b : c in other language Numbers Numerals type(3) --> number type(3.0) --> number math.type(3) --> integer math.type(3.0) --> float 0xff --> 255 0x0.2 --> 0.125 0x1p-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 float e1 - e2 e1 * e2 e1 / e2 --> always type float e1 // e2 --> floor divition. always rounds the quotient towards minus infinity -- Type is integer if both e1 and e2 are integers else float e1 % e2 --> modulo operator. equiv to `e1 - ((e1 // e2) * e2)` e1 ^ e2 --> exponential. always type float Relational Operators e1 < e2 e1 > e2 e1 <= e2 e1 >= e2 e1 == e2 e1 ~= e2 Strings -- string in lua is immutable a = "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"