Expand description
Module provides FFI bindings for the following constants, types and functions, realted to Lua C API:
- Plain lua C API
- lauxlib
- Lua utitlites, implemented in Tarantool
Structs§
Constants§
- CTID_
A_ CCHAR - CTID_
BOOL - CTID_
CCHAR - CTID_
COMPLEX_ DOUBLE - CTID_
COMPLEX_ FLOAT - CTID_
CTYPEID - CTID_
CVOID - CTID_
DOUBLE - CTID_
FLOAT - CTID_
INT8 - CTID_
INT16 - CTID_
INT32 - CTID_
INT64 - CTID_
NONE - CTID_
P_ CCHAR - CTID_
P_ CVOID - CTID_
P_ VOID - CTID_
UINT8 - CTID_
UINT16 - CTID_
UINT32 - CTID_
UINT64 - CTID_
VOID - LUA_
ENVIRONINDEX - LUA_
ERRERR - LUA_
ERRMEM - LUA_
ERRRUN - LUA_
ERRSYNTAX - LUA_
GLOBALSINDEX - LUA_
MINSTACK - LUA_
MULTRET - LUA_
NOREF - LUA_OK
- LUA_
REFNIL - LUA_
REGISTRYINDEX - Lua provides a registry, a pre-defined table that can be used by any C code
to store whatever Lua value it needs to store. This table is always located
at pseudo-index
LUA_REGISTRYINDEX. Any C library can store data into this table, but it should take care to choose keys different from those used by other libraries, to avoid collisions. Typically, you should use as key a string containing your library name or a light userdata with the address of a C object in your code. - LUA_
TBOOLEAN - LUA_
TCDATA - LUA_
TFUNCTION - LUA_
TLIGHTUSERDATA - LUA_
TNIL - LUA_
TNONE - LUA_
TNUMBER - LUA_
TSTRING - LUA_
TTABLE - LUA_
TTHREAD - LUA_
TUSERDATA - LUA_
YIELD
Functions§
- is_
relative_ index - luaL_
checkcdata ⚠ - Checks whether the function argument
idxis a cdata - luaL_
ctypeid ⚠ - Return CTypeID (FFI) of given CDATA type
ctypenameis a C type name as string (e.g. “struct request”, “uint32_t”, etc.). - luaL_
error ⚠ - Raises an error. The error message format is given by
fmtplus any extra arguments, following the same rules oflua_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. [-0, +0, v] - luaL_
getmetafield ⚠ - Push the metafield
fieldof the value at givenindexonto the stack. Returns1if the value was pushed,0otherwise. [-0, +(1|0), -] - luaL_
hasmetafield ⚠ - Check if value at given
indexhas metafieldfield. [-0, +0, -] - luaL_
iscallable ⚠ - Check if value at
indexis a lua function, a lua value with a__callmetamethod or a callablecdata. - luaL_
iscdata ⚠ - luaL_
newstate ⚠ - luaL_
openlibs ⚠ - luaL_
pushcdata ⚠ - Push cdata of given
ctypeidonto the stack. CTypeID must be used from FFI at least once. Allocated memory returned uninitialized. Only numbers and pointers are supported. - luaL_
pushint64 ⚠ - Push
i64onto the stack [-0, +1, -] - luaL_
pushuint64 ⚠ - Push
u64onto the stack [-0, +1, -] - luaL_
ref ⚠ - Creates and returns a reference, in the table at index
t, for the object at the top of the stack (and pops the object). [-1, +0, m] - luaL_
register ⚠ - luaL_
toint64 ⚠ - Checks whether the argument
idxis ai64or a convertable string and returns this number. [-0, +0, -] - luaL_
touint64 ⚠ - Checks whether the argument
idxis au64or a convertable string and returns this number. [-0, +0, -] - luaL_
unref ⚠ - Releases reference
rfrom the table at indext(seeluaL_ref). The entry is removed from the table, so that the referred object can be collected. The referenceris also freed to be used again. [-0, +0, -] - luaT_
tolstring ⚠ - Convert the value at
idxto string using__tostringmetamethod if other measures didn’t work and return it. Sets thelenif it’s notNULL. The newly created string is left on top of the stack. [-0, +1, m] - lua_
atpanic ⚠ - lua_
close ⚠ - lua_
concat ⚠ - lua_
cpcall ⚠ - Calls the C function
funcin protected mode.funcstarts with only one element in its stack, a light userdata containingud. In case of errors, lua_cpcall returns the same error codes as lua_pcall, plus the error object on the top of the stack; otherwise, it returns zero, and does not change the stack. All values returned byfuncare discarded. [-0, +(0|1), -] - lua_
createtable ⚠ - Creates a new empty table and pushes it onto the stack. The new table
has space pre-allocated for
narrarray elements andnrecnon-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the functionlua_newtable. [-0, +1, m] - lua_
dump ⚠ - lua_
error ⚠ - Generates a Lua error. The error message (which can actually be a Lua
value of any type) must be on the stack top. This function does a long
jump, and therefore never returns. (see
luaL_error). [-1, +0, v] - lua_
getfield ⚠ - Pushes onto the stack the value
t[k], wheretis the value at the given validindex. As in Lua, this function may trigger a metamethod for the “index” event [-0, +1, e] - lua_
getglobal ⚠ - Pushes onto the stack the value of the global
name. [-0, +1, e] - lua_
getmetatable ⚠ - lua_
gettable ⚠ - Pushes onto the stack the value
t[k], wheretis the value at the given validindexandkis the value at the top of the stack. [-1, +1, e] - lua_
gettop ⚠ - Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack). [-0, +0, -]
- lua_
insert ⚠ - Moves the top element into the given valid
index, shifting up the elements above thisindexto open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. [-1, +1, -] - lua_
isboolean ⚠ - lua_
isfunction ⚠ - lua_
islightuserdata ⚠ - lua_
isnil ⚠ - lua_
isnone ⚠ - lua_
isnoneornil ⚠ - lua_
isnumber ⚠ - lua_
istable ⚠ - lua_
isthread ⚠ - lua_len⚠
- lua_
load ⚠ - [-0, +1, -]
Loads a Lua chunk. If there are no errors,
lua_loadpushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message. The return values oflua_loadare: - lua_
loadx ⚠ - lua_
newstate ⚠ - lua_
newtable ⚠ - Creates a new empty table and pushes it onto the stack. It is equivalent to
lua_createtable(l, 0, 0). [-0, +1, m] - lua_
newthread ⚠ - Creates a new thread, pushes it on the stack, and returns a pointer to a
lua_Statethat represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack. [-0, +1, m] - lua_
newuserdata ⚠ - This function allocates a new block of memory with the given size, pushes onto the stack a new full userdata with the block address, and returns this address. [-0, +1, m]
- lua_
next ⚠ - 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, thenlua_nextreturns 0 (and pushes nothing). [-1, +(2|0), e] - lua_
pcall ⚠ - Calls a function in protected mode. [-(nargs + 1), +(nresults|1), -]
- lua_pop⚠
- lua_
pushboolean ⚠ - lua_
pushcclosure ⚠ - Pushes a new C closure onto the stack. [-n, +1, m]
- lua_
pushcfunction ⚠ - Pushes a C function onto the stack. This function receives a pointer to a C function and pushes onto the stack a Lua value of type function that, when called, invokes the corresponding C function. [-0, +1, m]
- lua_
pushglobaltable ⚠ - lua_
pushinteger ⚠ - Pushes a number with value
nonto the stack. [-0, +1, -] - lua_
pushlightuserdata ⚠ - Pushes a light userdata onto the stack. [-0, +1, -]
- lua_
pushlstring ⚠ - lua_
pushnil ⚠ - lua_
pushnumber ⚠ - Pushes a number with value
nonto the stack. [-0, +1, -] - lua_
pushstring ⚠ - Pushes the zero-terminated string pointed to by
sonto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string cannot contain embedded zeros; it is assumed to end at the first zero. [-0, +1, m] - lua_
pushvalue ⚠ - Pushes a copy of the element at the given valid
indexonto the stack. [-0, +1, -] - lua_
rawget ⚠ - Similar to
lua_gettable, but does a raw access (i.e., without metamethods). [-1, +1, -] - lua_
rawgeti ⚠ - Pushes onto the stack the value
t[n], wheretis the value at the given validindex. The access is raw; that is, it does not invoke metamethods. [-0, +1, -] - lua_
rawset ⚠ - Similar to
lua_settable, but does a raw assignment (i.e., without metamethods). [-2, +0, m] - lua_
rawseti ⚠ - Does the equivalent of
t[n] = v, wheretis the value at the given validindexandvis the value at the top of the stack. [-1, +0, m] - lua_
remove ⚠ - Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. [-1, +0, -]
- lua_
setfield ⚠ - Does the equivalent to
t[k] = v, wheretis the value at the given valid index andvis the value at the top of the stack. [-1, +0, e] - lua_
setglobal ⚠ - Pops a value from the stack and sets it as the new value of global
name. [-1, +0, e] - lua_
setmetatable ⚠ - Pops a table from the stack and sets it as the new metatable for the
value at the given acceptable
index. [-1, +0, -] - lua_
settable ⚠ - Does the equivalent to
t[k] = v, wheretis the value at the given validindex,vis the value at the top of the stack, andkis the value just below the top. [-2, +0, e] - lua_
settop ⚠ - lua_
toboolean ⚠ - lua_
tointeger ⚠ - lua_
tointegerx ⚠ - lua_
tolstring ⚠ - Converts the Lua value at the given acceptable
indexto a C string. Iflenis not NULL, it also sets*lenwith the string length. The Lua value must be a string or a number; otherwise, the function returns NULL. If the value is a number, thenlua_tolstringalso changes the actual value in the stack to a string. (This change confuseslua_nextwhenlua_tolstringis applied to keys during a table traversal.) [-0, +0, m] - lua_
tonumber ⚠ - lua_
tonumberx ⚠ - lua_
tostring ⚠ - lua_
touserdata ⚠ - If the value at the given acceptable
indexis a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returnsNULL. [-0, +0, -] - lua_
type ⚠ - Returns the type of the value in the given acceptable
index, orLUA_TNONEfor a non-valid index (that is, an index to an “empty” stack position). The types returned by lua_type are coded by the following constants:LUA_TNIL,LUA_TNUMBER,LUA_TBOOLEAN,LUA_TSTRING,LUA_TTABLE,LUA_TFUNCTION,LUA_TUSERDATA,LUA_TTHREAD, andLUA_TLIGHTUSERDATA. [-0, +0, -] - lua_
typename ⚠ - Returns the name of the type encoded by the value
tp, which must be one the values returned bylua_type. [-0, +0, -] - lua_
upvalueindex - When a C function is created, it is possible to associate some values with
it, thus creating a C closure; these values are called upvalues and are
accessible to the function whenever it is called (see
lua_pushcclosure). - lua_
version ⚠ - luaopen_
base ⚠ - luaopen_
bit ⚠ - luaopen_
debug ⚠ - luaopen_
io ⚠ - luaopen_
math ⚠ - luaopen_
os ⚠ - luaopen_
package ⚠ - luaopen_
string ⚠ - luaopen_
table ⚠
Type Aliases§
- CTypeID
- lua_
Alloc - lua_
CFunction - Type for C functions.
- lua_
Integer - lua_
Number - lua_
Reader - The reader function used by
lua_load. Every time it needs another piece of the chunk,lua_loadcalls the reader, passing along itsdataparameter. The reader must return a pointer to a block of memory with a new piece of the chunk and setsizeto the block size. The block must exist until the reader function is called again. To signal the end of the chunk, the reader must returnNULLor setsizeto zero. The reader function may return pieces of any size greater than zero. - lua_
Writer