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_optinteger
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_optinteger[-0, +0, v] lua_Integer luaL_optinteger (lua_State *L, int arg

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_setmetatable
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_setmetatable[-0, +0, –] void luaL_setmetatable (lua_State *L, const char *tname); Sets the metatable

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

luaL_checkversion[-0, +0, v] void luaL_checkversion (lua_State *L); Checks whether the core running

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_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_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
luaL_argcheck
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_argcheck[-0, +0, v] void luaL_argcheck (lua_State *L, int cond,

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

luaL_len[-0, +0, e] lua_Integer luaL_len (lua_State *L, int index); Returns the "length" of the

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

luaL_newstate[-0, +0, –] lua_State *luaL_newstate (void); Creates a new Lua state. It calls

2025-01-10 15:47:30