Module ffi

Module ffi 

Source
Expand description

Module provides FFI bindings for the following constants, types and functions, realted to Lua C API:

  1. Plain lua C API
  2. lauxlib
  3. Lua utitlites, implemented in Tarantool

Structs§

luaL_Reg
lua_State

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 idx is a cdata
luaL_ctypeid
Return CTypeID (FFI) of given CDATA type ctypename is 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 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. [-0, +0, v]
luaL_getmetafield
Push the metafield field of the value at given index onto the stack. Returns 1 if the value was pushed, 0 otherwise. [-0, +(1|0), -]
luaL_hasmetafield
Check if value at given index has metafield field. [-0, +0, -]
luaL_iscallable
Check if value at index is a lua function, a lua value with a __call metamethod or a callable cdata.
luaL_iscdata
luaL_newstate
luaL_openlibs
luaL_pushcdata
Push cdata of given ctypeid onto the stack. CTypeID must be used from FFI at least once. Allocated memory returned uninitialized. Only numbers and pointers are supported.
luaL_pushint64
Push i64 onto the stack [-0, +1, -]
luaL_pushuint64
Push u64 onto 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 idx is a i64 or a convertable string and returns this number. [-0, +0, -]
luaL_touint64
Checks whether the argument idx is a u64 or a convertable string and returns this number. [-0, +0, -]
luaL_unref
Releases reference r from the table at index t (see luaL_ref). The entry is removed from the table, so that the referred object can be collected. The reference r is also freed to be used again. [-0, +0, -]
luaT_tolstring
Convert the value at idx to string using __tostring metamethod if other measures didn’t work and return it. Sets the len if it’s not NULL. 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 func in protected mode. func starts with only one element in its stack, a light userdata containing ud. 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 by func are 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 narr array elements and nrec non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function lua_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], where t is the value at the given valid index. 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], where t is the value at the given valid index and k is 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 this index to 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_load pushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message. The return values of lua_load are:
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_State that 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, then lua_next returns 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 n onto 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 n onto the stack. [-0, +1, -]
lua_pushstring
Pushes the zero-terminated string pointed to by s onto 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 index onto 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], where t is the value at the given valid index. 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, where t is the value at the given valid index and v is 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, where t is the value at the given valid index and v is 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, where t is the value at the given valid index, v is the value at the top of the stack, and k is 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 index to a C string. If len is not NULL, it also sets *len with the string length. The Lua value must be a string or a number; otherwise, the function returns NULL. If the value is a number, then lua_tolstring also changes the actual value in the stack to a string. (This change confuses lua_next when lua_tolstring is 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 index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL. [-0, +0, -]
lua_type
Returns the type of the value in the given acceptable index, or LUA_TNONE for 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, and LUA_TLIGHTUSERDATA. [-0, +0, -]
lua_typename
Returns the name of the type encoded by the value tp, which must be one the values returned by lua_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_load calls the reader, passing along its data parameter. The reader must return a pointer to a block of memory with a new piece of the chunk and set size to the block size. The block must exist until the reader function is called again. To signal the end of the chunk, the reader must return NULL or set size to zero. The reader function may return pieces of any size greater than zero.
lua_Writer