require()

require (modname) Loads the given module. The function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module. To find a loader, require is guided by the package.searchers sequence. By changing this sequence, we can change how require looks for a module. The following explanation is based on the default configuration for pac

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

rawset()

rawset (table, index, value)table[index]value__newindextableindexnilvalue This function returns table.

table.sort()

table.sort (list [, comp]) Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that, after the sort, i < j implies not comp(list[j],list[i])). If comp is not given, then the standard Lua operator < is used instead. Note that the comp function must define a strict partial order over the elements

package.loadlib()

package.loadlib (libname, funcname) Dynamically links the host program with the C library libname. If funcname is "*", then it only links with the library, making the symbols exported by the library available to other dynamically linked libraries. Otherwise, it looks for a function funcname inside the library and returns this function as a C function. So, funcname must follow the lua_CFunction prototype (see lua_CFunction). This is a low-level function. It completely bypasses the package

luaL_checkudata

luaL_checkudata[-0, +0, v] void *luaL_checkudata (lua_State *L, int arg, const char *tname); Checks whether the function argument arg is a userdata of the type tname (see luaL_newmetatable) and returns the userdata address (see lua_touserdata).

lua_pushfstring

lua_pushfstring[-0, +1, e] const char *lua_pushfstring (lua_State *L, const char *fmt, ...); Pushes onto the stack a formatted string and returns a pointer to this string. It is similar to the ISO C function sprintf, but has some important differences: You do not have to allocate space for the result: the result is a Lua string and Lua takes care of memory allocation (and deallocation, through garbage collection). The conversion specifiers are quite restricted. There are no flags, widths

luaL_checknumber

luaL_checknumber[-0, +0, v] lua_Number luaL_checknumber (lua_State *L, int arg); Checks whether the function argument arg is a number and returns this number.

lua_createtable

lua_createtable[-0, +1, m] void lua_createtable (lua_State *L, int narr, int nrec); Creates a new empty table and pushes it onto the stack. Parameter narr is a hint for how many elements the table will have as a sequence; parameter nrec is a hint for how many other elements the table will have. Lua may use these hints to preallocate memory for the new table. This preallocation is useful for performance when you know in advance how many elements the table will have. Otherwise you can use the

lua_next

lua_next[-1, +(2|0), e] int lua_next (lua_State *L, int index); Pops a key from the stack, and pushes a key–value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns 0 (and pushes nothing). A typical traversal looks like this: /* table is in the stack at index 't' */ lua_pushnil(L); /* first key */ while (lua_next(L, t) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ printf("%