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

luaL_callmeta[-0, +(0|1), e] int luaL_callmeta (lua_State *L, int obj, const char *e); Calls a

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

luaL_optnumber[-0, +0, v] lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d); If

2025-01-10 15:47:30
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_checknumber
  • References/Lua/Lua/Auxiliary Library/Functions and Types

luaL_checknumber[-0, +0, v] lua_Number luaL_checknumber (lua_State *L, int arg); Checks whether

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

luaL_getmetafield[-0, +(0|1), m] int luaL_getmetafield (lua_State *L, int obj, const char *e);

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

luaL_newlibtable[-0, +1, m] void luaL_newlibtable (lua_State *L, const luaL_Reg l[]); Creates

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

luaL_loadfilex[-0, +1, m] int luaL_loadfilex (lua_State *L, const char *filename,

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