Module tlua::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

Constants

Functions

  • Checks whether the function argument idx is a cdata
  • Return CTypeID (FFI) of given CDATA type ctypename is a C type name as string (e.g. “struct request”, “uint32_t”, etc.). See also: luaL_pushcdata, luaL_checkcdata
  • 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]
  • 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), -]
  • Check if value at given index has metafield field. [-0, +0, -]
  • Check if value at index is a lua function, a lua value with a __call metamethod or a callable cdata.
  • 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.
  • Push i64 onto the stack [-0, +1, -]
  • Push u64 onto the stack [-0, +1, -]
  • 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]
  • Checks whether the argument idx is a i64 or a convertable string and returns this number. [-0, +0, -]
  • Checks whether the argument idx is a u64 or a convertable string and returns this number. [-0, +0, -]
  • 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, -]
  • 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]
  • 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), -]
  • 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]
  • 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]
  • 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]
  • Pushes onto the stack the value of the global name. [-0, +1, e]
  • 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]
  • 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, -]
  • 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, -]
  • [-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:
  • Creates a new empty table and pushes it onto the stack. It is equivalent to lua_createtable(L, 0, 0). [-0, +1, m]
  • 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]
  • 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]
  • 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]
  • Calls a function in protected mode. [-(nargs + 1), +(nresults|1), -]
  • Pushes a new C closure onto the stack. [-n, +1, m]
  • 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]
  • Pushes a number with value n onto the stack. [-0, +1, -]
  • Pushes a light userdata onto the stack. [-0, +1, -]
  • Pushes a number with value n onto the stack. [-0, +1, -]
  • 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]
  • Pushes a copy of the element at the given valid index onto the stack. [-0, +1, -]
  • Similar to lua_gettable, but does a raw access (i.e., without metamethods). [-1, +1, -]
  • 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, -]
  • Similar to lua_settable, but does a raw assignment (i.e., without metamethods). [-2, +0, m]
  • 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]
  • 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, -]
  • 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]
  • Pops a value from the stack and sets it as the new value of global name. [-1, +0, e]
  • Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index. [-1, +0, -]
  • 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]
  • 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]
  • 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, -]
  • 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, -]
  • Returns the name of the type encoded by the value tp, which must be one the values returned by lua_type. [-0, +0, -]
  • 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).

Type Aliases

  • Type for C functions.
  • 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.