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

luaL_optstring[-0, +0, v] const char *luaL_optstring (lua_State *L, int arg

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

luaL_newlib[-0, +1, m] void luaL_newlib (lua_State *L, const luaL_Reg l[]); Creates a new table

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

luaL_pushresultsize[-?, +1, m] void luaL_pushresultsize (luaL_Buffer *B, size_t sz); Equivalent

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

luaL_testudata[-0, +0, m] void *luaL_testudata (lua_State *L, int arg, const char *tname); This

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_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_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