C API reference
The embedding interface of liblus. Writing Lus instead? See the standard library reference.
legend
types lus_PledgeGranter lus_PledgeRequest
functions lus_checkfsperm lus_haspledge lus_initpledge lus_issealed lus_nextpledge lus_pledge lus_pledgeerror lus_registerpledge lus_rejectpledge lus_rejectrequest lus_revokepledge lus_setpledge
constants LUS_PLEDGE_CHECK LUS_PLEDGE_GRANT LUS_PLEDGE_UPDATE
types lus_WorkerSetup
functions lus_onworker lus_worker_create lus_worker_pool_init lus_worker_pool_shutdown lus_worker_receive lus_worker_send lus_worker_status
constants LUS_WORKER_BLOCKED LUS_WORKER_DEAD LUS_WORKER_ERROR LUS_WORKER_RUNNING
macros luaL_openlibs
functions luaL_openselectedlibs luaopen_base luaopen_coroutine luaopen_debug luaopen_fs luaopen_io luaopen_json luaopen_math luaopen_network luaopen_os luaopen_package luaopen_string luaopen_table luaopen_utf8 luaopen_vector luaopen_worker
constants LUA_COLIBK LUA_DBLIBK LUA_FSLIBK LUA_GLIBK LUA_IOLIBK LUA_LOADLIBK LUA_MATHLIBK LUA_NETLIBK LUA_OSLIBK LUA_STRLIBK LUA_TABLIBK LUA_UTF8LIBK LUA_VECLIBK LUA_WORKERLIBK
types lua_Alloc lua_CFunction lua_Debug lua_Hook lua_Integer lua_KContext lua_KFunction lua_Number lua_Reader lua_State lua_Unsigned lua_WarnFunction lua_Writer
macros lua_call lua_getextraspace lua_getuservalue lua_insert lua_isboolean lua_isenum lua_isfunction lua_islightuserdata lua_isnil lua_isnone lua_isnoneornil lua_istable lua_isthread lua_isvector lua_newtable lua_newuserdata lua_pcall lua_pop lua_pushcfunction lua_pushglobaltable lua_pushliteral lua_register lua_remove lua_replace lua_setuservalue lua_tointeger lua_tonumber lua_tostring lua_upvalueindex lua_yield
functions lua_absindex lua_arith lua_atpanic lua_callk lua_checkstack lua_close lua_closeslot lua_closethread lua_compacttable lua_compare lua_concat lua_copy lua_createtable lua_dump lua_error lua_gc lua_getallocf lua_getfield lua_getglobal lua_gethook lua_gethookcount lua_gethookmask lua_geti lua_getinfo lua_getiuservalue lua_getlocal lua_getmetatable lua_getstack lua_gettable lua_gettop lua_getupvalue lua_iscfunction lua_isinteger lua_isnumber lua_isstring lua_isuserdata lua_isyieldable lua_len lua_load lua_newstate lua_newthread lua_newuserdatauv lua_next lua_numbertocstring lua_pcallk lua_pushboolean lua_pushcclosure lua_pushenum lua_pushexternalstring lua_pushfstring lua_pushinteger lua_pushlightuserdata lua_pushlstring lua_pushnil lua_pushnumber lua_pushstring lua_pushthread lua_pushvalue lua_pushvfstring lua_rawequal lua_rawget lua_rawgeti lua_rawgetp lua_rawlen lua_rawset lua_rawseti lua_rawsetp lua_resume lua_rotate lua_setallocf lua_setfield lua_setglobal lua_sethook lua_seti lua_setiuservalue lua_setlocal lua_setmetatable lua_settable lua_settop lua_setupvalue lua_setwarnf lua_status lua_stringtonumber lua_toboolean lua_tocfunction lua_toclose lua_tointegerx lua_tolstring lua_tonumberx lua_topointer lua_tothread lua_touserdata lua_type lua_typename lua_upvalueid lua_upvaluejoin lua_version lua_warning lua_xmove lua_yieldk
constants LUA_ERRERR LUA_ERRMEM LUA_ERRRUN LUA_ERRSYNTAX LUA_GCCOLLECT LUA_GCCOUNT LUA_GCCOUNTB LUA_GCGEN LUA_GCINC LUA_GCISRUNNING LUA_GCPARAM LUA_GCRESTART LUA_GCSTEP LUA_GCSTOP LUA_HOOKCALL LUA_HOOKCOUNT LUA_HOOKLINE LUA_HOOKRET LUA_HOOKTAILCALL LUA_MASKCALL LUA_MASKCOUNT LUA_MASKLINE LUA_MASKRET LUA_MINSTACK LUA_MULTRET LUA_NUMTYPES LUA_OK LUA_OPADD LUA_OPBAND LUA_OPBNOT LUA_OPBOR LUA_OPBXOR LUA_OPDIV LUA_OPEQ LUA_OPIDIV LUA_OPLE LUA_OPLT LUA_OPMOD LUA_OPMUL LUA_OPPOW LUA_OPSHL LUA_OPSHR LUA_OPSUB LUA_OPUNM LUA_REGISTRYINDEX LUA_RIDX_GLOBALS LUA_RIDX_MAINTHREAD LUA_TBOOLEAN LUA_TENUM LUA_TFUNCTION LUA_TLIGHTUSERDATA LUA_TNIL LUA_TNONE LUA_TNUMBER LUA_TSTRING LUA_TTABLE LUA_TTHREAD LUA_TUSERDATA LUA_TVECTOR
types luaL_Buffer luaL_Reg luaL_Stream
macros luaL_addchar luaL_addsize luaL_argcheck luaL_argexpected luaL_buffaddr luaL_bufflen luaL_buffsub luaL_checkstring luaL_checkversion luaL_dofile luaL_dostring luaL_getmetatable luaL_loadbuffer luaL_loadfile luaL_newlib luaL_newlibtable luaL_optstring luaL_prepbuffer luaL_pushfail luaL_typename
functions luaL_addgsub luaL_addlstring luaL_addstring luaL_addvalue luaL_alloc luaL_argerror luaL_buffinit luaL_buffinitsize luaL_callmeta luaL_checkany luaL_checkinteger luaL_checklstring luaL_checknumber luaL_checkoption luaL_checkstack luaL_checktype luaL_checkudata luaL_checkversion_ luaL_error luaL_execresult luaL_fileresult luaL_getmetafield luaL_getsubtable luaL_gsub luaL_len luaL_loadbufferx luaL_loadfilex luaL_loadstring luaL_makeseed luaL_newmetatable luaL_newstate luaL_optinteger luaL_optlstring luaL_optnumber luaL_prepbuffsize luaL_pushresult luaL_pushresultsize luaL_ref luaL_requiref luaL_setfuncs luaL_setmetatable luaL_testudata luaL_tolstring luaL_traceback luaL_typeerror luaL_unref luaL_where
constants LUA_ERRFILE LUA_FILEHANDLE LUA_NOREF LUA_REFNIL LUAL_BUFFERSIZE LUAL_NUMSIZES
Permission System — C API
Convenience function for filesystem permission checks. Raises an error if denied.
Checks if a permission has been granted. Returns 1 if access is allowed, 0 if denied.
Initializes a pledge request for C-side grants. This bypasses granters and is used for direct permission grants from C code.
Returns 1 if the permission state is sealed, 0 otherwise.
Iterates through stored values for a permission. Sets p->current to the next stored value. Returns 1 if there are more values, 0 when done.
Grants a permission to the Lua state. Triggers the granter callback for validation. Returns 1 on success, 0 if denied or sealed.
Read-only permission check status code.
New permission request status code.
Updating existing permission status code.
Sets a denial error message for user-facing feedback.
Callback type for permission granters. Libraries register granters to handle their own permission validation logic.
Granters should call lus_setpledge to confirm valid permissions. Unprocessed requests are automatically denied.
Request structure passed to granter callbacks. Contains all information about the permission being granted or checked.
status indicates the operation: LUS_PLEDGE_GRANT for new grants, LUS_PLEDGE_UPDATE for updates, LUS_PLEDGE_CHECK for access checks.
Registers a granter callback for a permission namespace.
Permanently rejects a permission by name. Returns 1 on success, 0 if sealed.
Permanently rejects a permission using the request struct. Future attempts to grant this permission will fail.
Revokes a previously granted permission. Returns 1 on success, 0 if sealed or not found.
Confirms or sets a pledge value. Marks the request as processed, preventing automatic denial.
Worker System — C API
Registers a callback to be invoked when new worker states are created.
Worker status: blocked waiting for message.
Creates a new worker running the script at path.
Worker status: finished execution.
Worker status: terminated with error.
Initializes the global worker thread pool. Called automatically on first worker.create().
Shuts down the worker thread pool. Waits for all threads to complete.
Receives a message from the worker’s outbox. Pushes the message onto the stack.
Worker status: running.
Sends the value at stack index idx to the worker’s inbox.
Returns the status of a worker (LUS_WORKER_RUNNING, LUS_WORKER_DEAD, etc.).
Callback type for worker state initialization. Called when a new worker is created, allowing embedders to configure the worker’s Lua state.
Library Openers
Bitmask for the coroutine library.
Bitmask for the debug library.
Bitmask for the fs library.
Bitmask for the base library.
Bitmask for the io library.
Bitmask for the package library.
Bitmask for the math library.
Bitmask for the network library.
Bitmask for the os library.
Bitmask for the string library.
Bitmask for the table library.
Bitmask for the utf8 library.
Bitmask for the vector library.
Bitmask for the worker library.
Opens all standard libraries.
Opens selected standard libraries. The load and preload bitmasks control which libraries to open or preload.
Opens the base library. Called automatically by luaL_openlibs.
Opens the coroutine library. Called automatically by luaL_openlibs.
Opens the debug library. Called automatically by luaL_openlibs.
Opens the fs library. Called automatically by luaL_openlibs.
Opens the io library. Called automatically by luaL_openlibs.
Opens the json library. Called automatically by luaL_openlibs.
Opens the math library. Called automatically by luaL_openlibs.
Opens the network library. Called automatically by luaL_openlibs.
Opens the os library. Called automatically by luaL_openlibs.
Opens the package library. Called automatically by luaL_openlibs.
Opens the string library. Called automatically by luaL_openlibs.
Opens the table library. Called automatically by luaL_openlibs.
Opens the utf8 library. Called automatically by luaL_openlibs.
Opens the vector library. Called automatically by luaL_openlibs.
Opens the worker library. Called automatically by luaL_openlibs.
Core C API
The type of the memory-allocation function used by Lua states.
Calls a function (macro for lua_callk with no continuation).
Type for C functions that can be registered with Lua.
Shrinks the internal storage of the table at the given index to fit its current contents. Removing keys never shrinks a table’s array or hash parts on its own; this releases the unused capacity. Raises an error if the table is readonly. Exposed to Lus code as table.compact.
A structure used to carry different pieces of information about a function or an activation record.
Status code for an error while running the message handler.
Status code for a memory allocation error.
Status code for a runtime error.
Status code for a syntax error.
GC option to perform a full collection cycle.
GC option to return total memory in use (Kbytes).
GC option to return remainder of memory in use (bytes).
GC option to switch to generational mode.
GC option to switch to incremental mode.
GC option to check if the collector is running.
GC option to set/get a GC parameter.
GC option to restart the collector.
GC option to perform an incremental step.
GC option to stop the collector.
Returns a pointer to a raw memory area associated with the given Lua state.
Compatibility macro. Gets the first user value of a userdata.
Debug hook event for function calls.
Debug hook event for instruction counts.
Debug hook event for new lines.
Debug hook event for function returns.
Debug hook event for tail calls.
Moves the top element into the given valid index, shifting up elements above.
Returns 1 if the value at the given index is a boolean.
Returns 1 if the value at the given index is an enum.
Returns 1 if the value at the given index is a function.
Returns 1 if the value at the given index is a light userdata.
Returns 1 if the value at the given index is nil.
Returns 1 if the given index is not valid.
Returns 1 if the given index is not valid or the value is nil.
Returns 1 if the value at the given index is a table.
Returns 1 if the value at the given index is a thread.
Returns 1 if the value at the given index is a vector.
Type for continuation functions.
Mask for call hook events.
Mask for count hook events.
Mask for line hook events.
Mask for return hook events.
Minimum Lua stack size guaranteed to be available.
Option for multiple returns in lua_call and lua_pcall.
Creates a new empty table and pushes it onto the stack.
Compatibility macro. Creates a new userdata with one user value.
Total number of type tags.
Status code for no errors.
Code for addition in lua_arith.
Code for bitwise AND in lua_arith.
Code for bitwise NOT in lua_arith.
Code for bitwise OR in lua_arith.
Code for bitwise XOR in lua_arith.
Code for float division in lua_arith.
Code for equality in lua_compare.
Code for floor division in lua_arith.
Code for less-or-equal in lua_compare.
Code for less-than in lua_compare.
Code for modulo in lua_arith.
Code for multiplication in lua_arith.
Code for exponentiation in lua_arith.
Code for left shift in lua_arith.
Code for right shift in lua_arith.
Code for subtraction in lua_arith.
Code for unary minus in lua_arith.
Deprecated. Calls a function in protected mode.
Deprecated. Use CPROTECT_BEGIN/CPROTECT_END macros instead.
Pushes a C function onto the stack (macro for lua_pushcclosure with 0 upvalues).
Pushes the global environment table onto the stack.
Pushes a literal string onto the stack.
The reader function used by lua_load.
Sets the C function f as the new value of global n.
Pseudo-index for the registry table.
Removes the element at the given valid index, shifting down elements above.
Moves the top element into the given valid index without shifting.
Registry index for the global environment table.
Registry index for the main thread.
Compatibility macro. Sets the first user value of a userdata.
An opaque structure that points to a thread and indirectly to the whole state of a Lua interpreter.
Tag for boolean values.
Tag for enum values.
Tag for function values.
Tag for light userdata.
Tag for nil values.
Tag for no value.
Tag for number values.
Converts the value at the given index to a lua_Integer.
Converts the value at the given index to a lua_Number.
Equivalent to lua_tolstring with len equal to NULL.
Tag for string values.
Tag for table values.
Tag for thread (coroutine) values.
Tag for full userdata.
Tag for vector values.
Returns the pseudo-index for the i-th upvalue of a C closure.
The type of warning functions.
The writer function used by lua_dump.
Yields a coroutine (macro for lua_yieldk with no continuation).
Auxiliary C API
Error code for file-related errors in luaL_loadfile.
Metatable name for file handles.
Special reference value representing no reference.
Special reference value representing a reference to nil.
Adds to the buffer a string of length s previously copied to the buffer area.
Checks whether cond is true. If not, raises an argument error.
Checks whether cond is true. If not, raises a type error.
Type for a string buffer. A string buffer allows C code to build Lua strings piecemeal.
The initial buffer size used by the buffer system.
Checks whether the function argument n is a string and returns it.
Checks that the code making the call and the Lua library being called are using the same version of Lua and compatible numeric types.
Loads and runs the given file.
Loads and runs the given string.
Pushes onto the stack the metatable associated with the name n in the registry.
Loads a buffer as a Lua chunk.
Loads a file as a Lua chunk (macro for luaL_loadfilex with NULL mode).
Creates a new table and registers the functions in l into it.
Creates a table with a size hint for the number of entries in l.
Encodes the size of integers and floats for version checking.
If the function argument n is a string, returns it; otherwise returns d.
Equivalent to luaL_prepbuffsize with LUAL_BUFFERSIZE.
Type for arrays of functions to be registered with luaL_setfuncs.
The internal structure used by the standard I/O library for file handles.
Returns the name of the type of the value at the given index.