string.gmatch()

string.gmatch (s, pattern)pattern§6.4.1spattern As an example, the following loop will iterate over all the words from string s, printing one per line: s = "hello world from Lua" for w in string.gmatch(s, "%a+") do print(w) end The next example collects all pairs key=value from the given string into a table: t = {} s = "from=world, to=Lua" for k, v in string.gmatch(s, "(%w+)=(%w+)") do t[k] = v end For this function, a caret '^' at the start of a pattern does not work as an anchor, as

file:flush()

file:flush () Saves any written data to file.

debug.sethook()

debug.sethook ([thread,] hook, mask [, count]) Sets the given function as a hook. The string mask and the number count describe when the hook will be called. The string mask may have any combination of the following characters, with the given meaning: 'c': the hook is called every time Lua calls a function; 'r': the hook is called every time Lua returns from a function; 'l': the hook is called every time Lua enters a new line of code. Moreover, with a count different from zero, the

lua_getmetatable

lua_getmetatable[-0, +(0|1), –] int lua_getmetatable (lua_State *L, int index); If the value at the given index has a metatable, the function pushes that metatable onto the stack and returns 1. Otherwise, the function returns 0 and pushes nothing on the stack.

luaL_Buffer

luaL_Buffer typedef struct luaL_Buffer luaL_Buffer; Type for a string buffer. A string buffer allows C code to build Lua strings piecemeal. Its pattern of use is as follows: First declare a variable b of type luaL_Buffer. Then initialize it with a call luaL_buffinit(L, &b). Then add string pieces to the buffer calling any of the luaL_add* functions. Finish by calling luaL_pushresult(&b). This call leaves the final string on the top of the stack. If you know beforehand the to

ipairs()

ipairs (t) Returns three values (an iterator function, the table t, and 0) so that the construction for i,v in ipairs(t) do body end will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the first nil value.

table.pack()

table.pack (···) Returns a new table with all parameters stored into keys 1, 2, etc. and with a field "n" with the total number of parameters. Note that the resulting table may not be a sequence.

lua_pushvalue

lua_pushvalue[-0, +1, –] void lua_pushvalue (lua_State *L, int index); Pushes a copy of the element at the given index onto the stack.

lua_yield

lua_yield[-?, +?, e] int lua_yield (lua_State *L, int nresults); This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield.

select()

select (index, ···) If index is a number, returns all arguments after argument number index; a negative number indexes from the end (-1 is the last argument). Otherwise, index must be the string "#", and select returns the total number of extra arguments it received.