print("Hello World")a = io.read("*n") -- read a number-- Chunksdofile("a.lua") -- immediately exec a file (usually used in interactive mode)-- Semicolonsa = 1; b = a * 2a = 1 b = a * 2 -- ugly, but valid-- Variablesb -- nil by default, can be used uninitialised-- Typestype(nil) --> niltype(true) --> booleantype(10.4 * 3) --> numbertype("Hello world") --> stringtype(io.stdin) --> userdatatype(print) --> functiontype(type) --> functiontype({}) --> tabletype(type(X)) --> string (no matter value of X)
Lua provides a REPL
lua -i prog starts the interactive REPL after executing prog contents
We call each piece of code that Lua executes, such as a file or a single line in interactive mode, a chunk. A chunk is simply a sequence of commands (or statements).
Identifiers (or names) in Lua can be any string of letters, digits, and underscores, not beginning with a digit; for instance
Identifier starting with _ are dummy vars
Semicolons can be used as delimiters but not needed