Bitwise Operators

3.4.2 – Bitwise Operators Lua supports the following bitwise operators: &: bitwise AND |: bitwise OR ~: bitwise exclusive OR >>: right shift <<: left shift ~: unary bitwise NOT All bitwise operations convert its operands to integers (see §3.4.3), operate on all bits of those integers, and result in an integer. Both right and left shifts fill the vacant bits with zeros. Negative displacements shift to the other direction; displacements with absolute values equal to o

math.min()

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

lua_Debug

lua_Debug typedef struct lua_Debug { int event; const char *name; /* (n) */ const char *namewhat; /* (n) */ const char *what; /* (S) */ const char *source; /* (S) */ int currentline; /* (l) */ int linedefined; /* (S) */ int lastlinedefined; /* (S) */ unsigned char nups; /* (u) number of upvalues */ unsigned char nparams; /* (u) number of parameters */ char isvararg; /* (u) */ char i

io.lines()

io.lines ([filename, ···]) Opens the given file name in read mode and returns an iterator function that works like file:lines(···) over the opened file. When the iterator function detects the end of file, it returns no values (to finish the loop) and automatically closes the file. The call io.lines() (with no file name) is equivalent to io.input():lines("*l"); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends. In case

lua_close

lua_close[-0, +0, –] void lua_close (lua_State *L); Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs that create multiple states, such as daemons or web servers, will probably need to close states as soon as t

lua_dump

lua_dump[-0, +0, –] int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip); Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk, lua_dump calls function writer (see lua_Writer) with the given data to write them. If strip is true, the bina

string.format()

string.format (formatstring, ···) Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the ISO C function sprintf. The only differences are that the options/modifiers *, h, L, l, n, and p are not supported and that there is an extra option, q. The q option formats a string between double quotes, using escape sequences when necessary to ensure that it can saf

lua_getlocal

lua_getlocal[-0, +(0|1), –] const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); Gets information about a local variable of a given activation record or a given function. In the first case, the parameter ar must be a valid activation record that was filled by a previous call to lua_getstack or given as argument to a hook (see lua_Hook). The index n selects which local variable to inspect; see debug.getlocal for details about variable indices and names. lua_getlocal pushes

Control Structures

3.3.4 – Control Structures The control structures if, while, and repeat have the usual meaning and familiar syntax: stat ::= while exp do block end stat ::= repeat block until exp stat ::= if exp then block {elseif exp then block} [else block] end Lua also has a for statement, in two flavors (see §3.3.5). The condition expression of a control structure can return any value. Both false and nil are considered false. All values different from nil and false are considered true (in particular,

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).