For Statement

3.3.5 – For Statement The for statement has two forms: one numerical and one generic. The numerical for loop repeats a block of code while a control variable runs through an arithmetic progression. It has the following syntax: stat ::= for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end The block is repeated for name starting at the value of the first exp, until it passes the second exp by steps of the third exp. More precisely, a for statement like for v = e1, e2, e3 do block end is equival

Format Strings for Pack and Unpack

6.4.2 – Format Strings for Pack and Unpack The first argument to string.pack, string.packsize, and string.unpack is a format string, which describes the layout of the structure being created or read. A format string is a sequence of conversion options. The conversion options are as follows: <: sets little endian >: sets big endian =: sets native endian ![n]: sets maximum alignment to n (default is native alignment) b: a signed byte (char) B: an unsigned byte (char) h: a signed

Function Calls

3.4.10 – Function Calls A function call in Lua has the following syntax: functioncall ::= prefixexp args In a function call, first prefixexp and args are evaluated. If the value of prefixexp has type function, then this function is called with the given arguments. Otherwise, the prefixexp "call" metamethod is called, having as first parameter the value of prefixexp, followed by the original call arguments (see §2.4). The form functioncall ::= prefixexp ‘:’ Name args can be used to call "

Function Calls as Statements

3.3.6 – Function Calls as Statements To allow possible side-effects, function calls can be executed as statements: stat ::= functioncall In this case, all returned values are thrown away. Function calls are explained in §3.4.10.

Function Definitions

3.4.11 – Function Definitions The syntax for function definition is functiondef ::= function funcbody funcbody ::= ‘(’ [parlist] ‘)’ block end The following syntactic sugar simplifies function definitions: stat ::= function funcname funcbody stat ::= local function Name funcbody funcname ::= Name {‘.’ Name} [‘:’ Name] The statement function f () body end translates to f = function () body end The statement function t.a.b.c.f () body end translates to t.a.b.c.f = function () body end

Garbage-Collection Metamethods

2.5.1 – Garbage-Collection Metamethods You can set garbage-collector metamethods for tables and, using the C API, for full userdata (see §2.4). These metamethods are also called finalizers. Finalizers allow you to coordinate Lua's garbage collection with external resource management (such as closing files, network or database connections, or freeing your own memory). For an object (table or userdata) to be finalized when collected, you must mark it for finalization. You mark an object for fi

getmetatable()

getmetatable (object) If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.

io.close()

io.close ([file]) Equivalent to file:close(). Without a file, closes the default output file.

io.flush()

io.flush () Equivalent to io.output():flush().

io.input()

io.input ([file]) When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file. In case of errors this function raises the error, instead of returning an error code.