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

math.ult()

math.ult (m, n) Returns a boolean, true if and only if integer m is below integer n when they are compared as unsigned integers.

file:read()

file:read (···) Reads the file file, according to the given formats, which specify what to read. For each format, the function returns a string or a number with the characters read, or nil if it cannot read data with the specified format. (In this latter case, the function does not read subsequent formats.) When called without formats, it uses a default format that reads the next line (see below). The available formats are "n": reads a numeral and returns it as a float or an integer, fol

lua_tointegerx

lua_tointegerx[-0, +0, –] lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum); Converts the Lua value at the given index to the signed integral type lua_Integer. The Lua value must be an integer, or a number or string convertible to an integer (see §3.4.3); otherwise, lua_tointegerx returns 0. If isnum is not NULL, its referent is assigned a boolean value that indicates whether the operation succeeded.

Arithmetic Operators

3.4.1 – Arithmetic Operators Lua supports the following arithmetic operators: +: addition -: subtraction *: multiplication /: float division //: floor division %: modulo ^: exponentiation -: unary minus With the exception of exponentiation and float division, the arithmetic operators work as follows: If both operands are integers, the operation is performed over integers and the result is an integer. Otherwise, if both operands are numbers or strings that can be converted to number

luaL_checkversion

luaL_checkversion[-0, +0, v] void luaL_checkversion (lua_State *L); Checks whether the core running the call, the core that created the Lua state, and the code making the call are all using the same version of Lua. Also checks whether the core running the call and the core that created the Lua state are using the same address space.

debug.getlocal()

debug.getlocal ([thread,] f, local) This function returns the name and the value of the local variable with index local of the function at level f of the stack. This function accesses not only explicit local variables, but also parameters, temporaries, etc. The first parameter or local variable has index 1, and so on, following the order that they are declared in the code, counting only the variables that are active in the current scope of the function. Negative indices refer to vararg para

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 "

lua_gethook

lua_gethook[-0, +0, –] lua_Hook lua_gethook (lua_State *L); Returns the current hook function.

luaL_optlstring

luaL_optlstring[-0, +0, v] const char *luaL_optlstring (lua_State *L, int arg, const char *d, size_t *l); If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error. If l is not NULL, fills the position *l with the result's length. If the result is NULL (only possible when returning d and d == NULL), its length is considered