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

os.date()

os.date ([format [, time]]) Returns a string or a table containing date and time, formatted according to the given string format. If the time argument is present, this is the time to be formatted (see the os.time function for a description of this value). Otherwise, date formats the current time. If format starts with '!', then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string "*t", then date returns a table with the following fiel

lua_pushcclosure

lua_pushcclosure[-n, +1, m] void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); Pushes a new C closure onto the stack. When a C function is created, it is possible to associate some values with it, thus creating a C closure (see §4.4); these values are then accessible to the function whenever it is called. To associate values with a C function, first these values must be pushed onto the stack (when there are multiple values, the first value is pushed first). Then lua_pushcclosur

luaL_error

luaL_error[-0, +0, v] int luaL_error (lua_State *L, const char *fmt, ...); Raises an error. The error message format is given by fmt plus any extra arguments, following the same rules of lua_pushfstring. It also adds at the beginning of the message the file name and the line number where the error occurred, if this information is available. This function never returns, but it is an idiom to use it in C functions as return luaL_error(args).

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

luaL_setfuncs

luaL_setfuncs[-nup, +0, m] void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); Registers all functions in the array l (see luaL_Reg) into the table on the top of the stack (below optional upvalues, see next). When nup is not zero, all functions are created sharing nup upvalues, which must be previously pushed on the stack on top of the library table. These values are popped from the stack after the registration.

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 "

Relational Operators

3.4.4 – Relational Operators Lua supports the following relational operators: ==: equality ~=: inequality <: less than >: greater than <=: less or equal >=: greater or equal These operators always result in false or true. Equality (==) first compares the type of its operands. If the types are different, then the result is false. Otherwise, the values of the operands are compared. Strings are compared in the obvious way. Numbers are equal if they denote the same mathemat

math.min()

math.min (x, ···) Returns the argument with the minimum value, according to the Lua operator <. (integer/float)

lua_yieldk

lua_yieldk[-?, +?, e] int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k); Yields a coroutine (thread). When a C function calls lua_yieldk, the running coroutine suspends its execution, and the call to lua_resume that started this coroutine returns. The parameter nresults is the number of values from the stack that will be passed as results to lua_resume. When the coroutine is resumed again, Lua calls the given co