5 – The Auxiliary Library

The auxiliary library provides several convenient functions to interface C with Lua. While the basic API provides the primitive functions for all interactions between C and Lua, the auxiliary library provides higher-level functions for some common tasks.

All functions and types from the auxiliary library are defined in header file lauxlib.h and have a prefix luaL_.

All functions in the auxiliary library are built on top of the basic API, and so they provide nothing that cannot be done with that API. Nevertheless, the use of the auxiliary library ensures more consistency to your code.

Several functions in the auxiliary library use internally some extra stack slots. When a function in the auxiliary library uses less than five slots, it does not check the stack size; it simply assumes that there are enough slots.

Several functions in the auxiliary library are used to check C function arguments. Because the error message is formatted for arguments (e.g., "bad argument #1"), you should not use these functions for other stack values.

Functions called luaL_check* always raise an error if the check is not satisfied.

luaL_unref
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_unref[-0, +0, –] void luaL_unref (lua_State *L, int t, int ref); Releases reference ref

2025-01-10 15:47:30
luaL_checkstack
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_checkstack[-0, +0, v] void luaL_checkstack (lua_State *L, int sz, const char *msg); Grows

2025-01-10 15:47:30
luaL_setfuncs
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_setfuncs[-nup, +0, m] void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); Registers

2025-01-10 15:47:30
luaL_execresult
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_execresult[-0, +3, m] int luaL_execresult (lua_State *L, int stat); This function produces

2025-01-10 15:47:30
luaL_getsubtable
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_getsubtable[-0, +1, e] int luaL_getsubtable (lua_State *L, int idx, const char *fname); Ensures

2025-01-10 15:47:30
luaL_addlstring
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_addlstring[-?, +?, m] void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); Adds

2025-01-10 15:47:30
luaL_dofile
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_dofile[-0, +?, e] int luaL_dofile (lua_State *L, const char *filename); Loads and runs the

2025-01-10 15:47:30
luaL_checkudata
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_checkudata[-0, +0, v] void *luaL_checkudata (lua_State *L, int arg, const char *tname); Checks

2025-01-10 15:47:30
luaL_ref
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_ref[-1, +0, m] int luaL_ref (lua_State *L, int t); Creates and returns a reference

2025-01-10 15:47:30
luaL_addsize
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_addsize[-?, +?, –] void luaL_addsize (luaL_Buffer *B, size_t n); Adds to the buffer B

2025-01-10 15:47:30