lus

C API reference

The embedding interface of liblus. Writing Lus instead? See the standard library reference.

legend
lus stable Lus addition
unstable unstable channel only
lua inherited from Lua
deprecated deprecated in Lus
removed removed in Lus
fastcall vm has special optimization

Core C API

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

Permission System — C API

int lus_checkfsperm (lua_State *L, const char *perm, const char *path)
since 0.1.0

Convenience function for filesystem permission checks. Raises an error if denied.

int lus_haspledge (lua_State *L, const char *name, const char *value)
since 0.1.0

Checks if a permission has been granted. Returns 1 if access is allowed, 0 if denied.

void lus_initpledge (lua_State *L, lus_PledgeRequest *p, const char *base)
since 0.1.0

Initializes a pledge request for C-side grants. This bypasses granters and is used for direct permission grants from C code.

int lus_issealed (lua_State *L)
since 0.1.0

Returns 1 if the permission state is sealed, 0 otherwise.

int lus_nextpledge (lua_State *L, lus_PledgeRequest *p)
since 0.1.0

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.

int lus_pledge (lua_State *L, const char *name, const char *value)
since 0.1.0

Grants a permission to the Lua state. Triggers the granter callback for validation. Returns 1 on success, 0 if denied or sealed.

since 0.1.0 · value: 2 (int)

Read-only permission check status code.

since 0.1.0 · value: 0 (int)

New permission request status code.

since 0.1.0 · value: 1 (int)

Updating existing permission status code.

void lus_pledgeerror (lua_State *L, lus_PledgeRequest *p, const char *msg)
since 0.1.0

Sets a denial error message for user-facing feedback.

typedef void (*lus_PledgeGranter)(lua_State *L, lus_PledgeRequest *p);
since 0.1.0

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.

typedef struct lus_PledgeRequest { const char *base; const char *sub; const char *value; const char *current; int status; int count; int has_base; } lus_PledgeRequest;
since 0.1.0

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.

void lus_registerpledge (lua_State *L, const char *name, lus_PledgeGranter granter)
since 0.1.0

Registers a granter callback for a permission namespace.

int lus_rejectpledge (lua_State *L, const char *name)
since 0.1.0

Permanently rejects a permission by name. Returns 1 on success, 0 if sealed.

void lus_rejectrequest (lua_State *L, lus_PledgeRequest *p)
since 0.1.0

Permanently rejects a permission using the request struct. Future attempts to grant this permission will fail.

int lus_revokepledge (lua_State *L, const char *name)
since 0.1.0

Revokes a previously granted permission. Returns 1 on success, 0 if sealed or not found.

void lus_setpledge (lua_State *L, lus_PledgeRequest *p, const char *sub, const char *value)
since 0.1.0

Confirms or sets a pledge value. Marks the request as processed, preventing automatic denial.

Worker System — C API

void lus_onworker (lua_State *L, lus_WorkerSetup fn)
since 0.1.0

Registers a callback to be invoked when new worker states are created.

since 0.1.0 · value: 1 (int)

Worker status: blocked waiting for message.

WorkerState *lus_worker_create (lua_State *L, const char *path)
since 0.1.0

Creates a new worker running the script at path.

since 0.1.0 · value: 2 (int)

Worker status: finished execution.

since 0.1.0 · value: 3 (int)

Worker status: terminated with error.

void lus_worker_pool_init (lua_State *L)
since 0.1.0

Initializes the global worker thread pool. Called automatically on first worker.create().

void lus_worker_pool_shutdown (void)
since 0.1.0

Shuts down the worker thread pool. Waits for all threads to complete.

int lus_worker_receive (lua_State *L, WorkerState *w)
since 0.1.0

Receives a message from the worker’s outbox. Pushes the message onto the stack.

since 0.1.0 · value: 0 (int)

Worker status: running.

int lus_worker_send (lua_State *L, WorkerState *w, int idx)
since 0.1.0

Sends the value at stack index idx to the worker’s inbox.

int lus_worker_status (WorkerState *w)
since 0.1.0

Returns the status of a worker (LUS_WORKER_RUNNING, LUS_WORKER_DEAD, etc.).

typedef void (*lus_WorkerSetup)(lua_State *parent, lua_State *worker);
since 0.1.0

Callback type for worker state initialization. Called when a new worker is created, allowing embedders to configure the worker’s Lua state.

Library Openers

since 0.1.0 · value: 4 (int)

Bitmask for the coroutine library.

since 0.1.0 · value: 8 (int)

Bitmask for the debug library.

since 0.1.0 · value: 1024 (int)

Bitmask for the fs library.

since 0.1.0 · value: 1 (int)

Bitmask for the base library.

since 0.1.0 · value: 16 (int)

Bitmask for the io library.

since 0.1.0 · value: 2 (int)

Bitmask for the package library.

since 0.1.0 · value: 32 (int)

Bitmask for the math library.

since 0.1.0 · value: 2048 (int)

Bitmask for the network library.

since 0.1.0 · value: 64 (int)

Bitmask for the os library.

since 0.1.0 · value: 128 (int)

Bitmask for the string library.

since 0.1.0 · value: 256 (int)

Bitmask for the table library.

since 0.1.0 · value: 512 (int)

Bitmask for the utf8 library.

since 0.1.0 · value: 8192 (int)

Bitmask for the vector library.

since 0.1.0 · value: 4096 (int)

Bitmask for the worker library.

#define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0)
since 0.1.0

Opens all standard libraries.

void luaL_openselectedlibs (lua_State *L, int load, int preload)
since 0.1.0

Opens selected standard libraries. The load and preload bitmasks control which libraries to open or preload.

int luaopen_base (lua_State *L)
since 0.1.0

Opens the base library. Called automatically by luaL_openlibs.

int luaopen_coroutine (lua_State *L)
since 0.1.0

Opens the coroutine library. Called automatically by luaL_openlibs.

int luaopen_debug (lua_State *L)
since 0.1.0

Opens the debug library. Called automatically by luaL_openlibs.

int luaopen_fs (lua_State *L)
since 0.1.0

Opens the fs library. Called automatically by luaL_openlibs.

int luaopen_io (lua_State *L)
since 0.1.0

Opens the io library. Called automatically by luaL_openlibs.

int luaopen_json (lua_State *L)
since 0.1.0

Opens the json library. Called automatically by luaL_openlibs.

int luaopen_math (lua_State *L)
since 0.1.0

Opens the math library. Called automatically by luaL_openlibs.

int luaopen_network (lua_State *L)
since 0.1.0

Opens the network library. Called automatically by luaL_openlibs.

int luaopen_os (lua_State *L)
since 0.1.0

Opens the os library. Called automatically by luaL_openlibs.

int luaopen_package (lua_State *L)
since 0.1.0

Opens the package library. Called automatically by luaL_openlibs.

int luaopen_string (lua_State *L)
since 0.1.0

Opens the string library. Called automatically by luaL_openlibs.

int luaopen_table (lua_State *L)
since 0.1.0

Opens the table library. Called automatically by luaL_openlibs.

int luaopen_utf8 (lua_State *L)
since 0.1.0

Opens the utf8 library. Called automatically by luaL_openlibs.

int luaopen_vector (lua_State *L)
since 0.1.0

Opens the vector library. Called automatically by luaL_openlibs.

int luaopen_worker (lua_State *L)
since 0.1.0

Opens the worker library. Called automatically by luaL_openlibs.

Core C API

int lua_absindex (lua_State *L, int idx)
since 0.1.0
typedef void *(*lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize);
since 0.1.0

The type of the memory-allocation function used by Lua states.

void lua_arith (lua_State *L, int op)
since 0.1.0
lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf)
since 0.1.0
#define lua_call(L,n,r) lua_callk(L,(n),(r),0,NULL)
since 0.1.0

Calls a function (macro for lua_callk with no continuation).

void lua_callk (lua_State *L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k)
since 0.1.0
typedef int (*lua_CFunction)(lua_State *L);
since 0.1.0

Type for C functions that can be registered with Lua.

int lua_checkstack (lua_State *L, int n)
since 0.1.0
void lua_close (lua_State *L)
since 0.1.0
void lua_closeslot (lua_State *L, int idx)
since 0.1.0
int lua_closethread (lua_State *L, lua_State *from)
since 0.1.0
void lua_compacttable (lua_State *L, int idx)
since 1.6.0

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.

int lua_compare (lua_State *L, int idx1, int idx2, int op)
since 0.1.0
void lua_concat (lua_State *L, int n)
since 0.1.0
void lua_copy (lua_State *L, int fromidx, int toidx)
since 0.1.0
void lua_createtable (lua_State *L, int narr, int nrec)
since 0.1.0
struct lua_Debug { int event; const char *name; const char *namewhat; const char *what; const char *source; size_t srclen; int currentline; int linedefined; int lastlinedefined; unsigned char nups; unsigned char nparams; char isvararg; unsigned char extraargs; char istailcall; int ftransfer; int ntransfer; char short_src[LUA_IDSIZE]; };
since 0.1.0

A structure used to carry different pieces of information about a function or an activation record.

int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip)
since 0.1.0
since 0.1.0 · value: 5 (int)

Status code for an error while running the message handler.

since 0.1.0 · value: 4 (int)

Status code for a memory allocation error.

int lua_error (lua_State *L)
since 0.1.0
since 0.1.0 · value: 2 (int)

Status code for a runtime error.

since 0.1.0 · value: 3 (int)

Status code for a syntax error.

int lua_gc (lua_State *L, int what, ...)
since 0.1.0
since 0.1.0 · value: 2 (int)

GC option to perform a full collection cycle.

since 0.1.0 · value: 3 (int)

GC option to return total memory in use (Kbytes).

since 0.1.0 · value: 4 (int)

GC option to return remainder of memory in use (bytes).

since 0.1.0 · value: 7 (int)

GC option to switch to generational mode.

since 0.1.0 · value: 8 (int)

GC option to switch to incremental mode.

since 0.1.0 · value: 6 (int)

GC option to check if the collector is running.

since 0.1.0 · value: 9 (int)

GC option to set/get a GC parameter.

since 0.1.0 · value: 1 (int)

GC option to restart the collector.

since 0.1.0 · value: 5 (int)

GC option to perform an incremental step.

since 0.1.0 · value: 0 (int)

GC option to stop the collector.

lua_Alloc lua_getallocf (lua_State *L, void **ud)
since 0.1.0
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
since 0.1.0

Returns a pointer to a raw memory area associated with the given Lua state.

int lua_getfield (lua_State *L, int idx, const char *k)
since 0.1.0
int lua_getglobal (lua_State *L, const char *name)
since 0.1.0
lua_Hook lua_gethook (lua_State *L)
since 0.1.0
int lua_gethookcount (lua_State *L)
since 0.1.0
int lua_gethookmask (lua_State *L)
since 0.1.0
int lua_geti (lua_State *L, int idx, lua_Integer n)
since 0.1.0
int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar)
since 0.1.0
int lua_getiuservalue (lua_State *L, int idx, int n)
since 0.1.0
const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n)
since 0.1.0
int lua_getmetatable (lua_State *L, int objindex)
since 0.1.0
int lua_getstack (lua_State *L, int level, lua_Debug *ar)
since 0.1.0
int lua_gettable (lua_State *L, int idx)
since 0.1.0
int lua_gettop (lua_State *L)
since 0.1.0
const char *lua_getupvalue (lua_State *L, int funcindex, int n)
since 0.1.0
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
since 0.1.0

Compatibility macro. Gets the first user value of a userdata.

typedef void (*lua_Hook)(lua_State *L, lua_Debug *ar);
since 0.1.0

Type for debugging hook functions.

since 0.1.0 · value: 0 (int)

Debug hook event for function calls.

since 0.1.0 · value: 3 (int)

Debug hook event for instruction counts.

since 0.1.0 · value: 2 (int)

Debug hook event for new lines.

since 0.1.0 · value: 1 (int)

Debug hook event for function returns.

since 0.1.0 · value: 4 (int)

Debug hook event for tail calls.

#define lua_insert(L,idx) lua_rotate(L,(idx),1)
since 0.1.0

Moves the top element into the given valid index, shifting up elements above.

typedef long long lua_Integer;
since 0.1.0

The type of integers in Lua.

#define lua_isboolean(L,n) (lua_type(L,(n)) == LUA_TBOOLEAN)
since 0.1.0

Returns 1 if the value at the given index is a boolean.

int lua_iscfunction (lua_State *L, int idx)
since 0.1.0
#define lua_isenum(L,n) (lua_type(L,(n)) == LUA_TENUM)
since 0.1.0

Returns 1 if the value at the given index is an enum.

#define lua_isfunction(L,n) (lua_type(L,(n)) == LUA_TFUNCTION)
since 0.1.0

Returns 1 if the value at the given index is a function.

int lua_isinteger (lua_State *L, int idx)
since 0.1.0
#define lua_islightuserdata(L,n) (lua_type(L,(n)) == LUA_TLIGHTUSERDATA)
since 0.1.0

Returns 1 if the value at the given index is a light userdata.

#define lua_isnil(L,n) (lua_type(L,(n)) == LUA_TNIL)
since 0.1.0

Returns 1 if the value at the given index is nil.

#define lua_isnone(L,n) (lua_type(L,(n)) == LUA_TNONE)
since 0.1.0

Returns 1 if the given index is not valid.

#define lua_isnoneornil(L,n) (lua_type(L,(n)) <= 0)
since 0.1.0

Returns 1 if the given index is not valid or the value is nil.

int lua_isnumber (lua_State *L, int idx)
since 0.1.0
int lua_isstring (lua_State *L, int idx)
since 0.1.0
#define lua_istable(L,n) (lua_type(L,(n)) == LUA_TTABLE)
since 0.1.0

Returns 1 if the value at the given index is a table.

#define lua_isthread(L,n) (lua_type(L,(n)) == LUA_TTHREAD)
since 0.1.0

Returns 1 if the value at the given index is a thread.

int lua_isuserdata (lua_State *L, int idx)
since 0.1.0
#define lua_isvector(L,n) (lua_type(L,(n)) == LUA_TVECTOR)
since 0.1.0

Returns 1 if the value at the given index is a vector.

int lua_isyieldable (lua_State *L)
since 0.1.0
typedef intptr_t lua_KContext;
since 0.1.0

The type for continuation-function contexts.

typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx);
since 0.1.0

Type for continuation functions.

void lua_len (lua_State *L, int idx)
since 0.1.0
int lua_load (lua_State *L, lua_Reader reader, void *dt, const char *chunkname, const char *mode)
since 0.1.0
since 0.1.0 · value: 1 (int)

Mask for call hook events.

since 0.1.0 · value: 8 (int)

Mask for count hook events.

since 0.1.0 · value: 4 (int)

Mask for line hook events.

since 0.1.0 · value: 2 (int)

Mask for return hook events.

since 0.1.0 · value: 20 (int)

Minimum Lua stack size guaranteed to be available.

since 0.1.0 · value: -1 (int)

Option for multiple returns in lua_call and lua_pcall.

lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed)
since 0.1.0
#define lua_newtable(L) lua_createtable(L, 0, 0)
since 0.1.0

Creates a new empty table and pushes it onto the stack.

lua_State *lua_newthread (lua_State *L)
since 0.1.0
#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
since 0.1.0

Compatibility macro. Creates a new userdata with one user value.

void *lua_newuserdatauv (lua_State *L, size_t sz, int nuvalue)
since 0.1.0
int lua_next (lua_State *L, int idx)
since 0.1.0
typedef double lua_Number;
since 0.1.0

The type of floats in Lua.

unsigned lua_numbertocstring (lua_State *L, int idx, char *buff)
since 0.1.0
since 0.1.0 · value: 11 (int)

Total number of type tags.

since 0.1.0 · value: 0 (int)

Status code for no errors.

since 0.1.0 · value: 0 (int)

Code for addition in lua_arith.

since 0.1.0 · value: 7 (int)

Code for bitwise AND in lua_arith.

since 0.1.0 · value: 13 (int)

Code for bitwise NOT in lua_arith.

since 0.1.0 · value: 8 (int)

Code for bitwise OR in lua_arith.

since 0.1.0 · value: 9 (int)

Code for bitwise XOR in lua_arith.

since 0.1.0 · value: 5 (int)

Code for float division in lua_arith.

since 0.1.0 · value: 0 (int)

Code for equality in lua_compare.

since 0.1.0 · value: 6 (int)

Code for floor division in lua_arith.

since 0.1.0 · value: 2 (int)

Code for less-or-equal in lua_compare.

since 0.1.0 · value: 1 (int)

Code for less-than in lua_compare.

since 0.1.0 · value: 3 (int)

Code for modulo in lua_arith.

since 0.1.0 · value: 2 (int)

Code for multiplication in lua_arith.

since 0.1.0 · value: 4 (int)

Code for exponentiation in lua_arith.

since 0.1.0 · value: 10 (int)

Code for left shift in lua_arith.

since 0.1.0 · value: 11 (int)

Code for right shift in lua_arith.

since 0.1.0 · value: 1 (int)

Code for subtraction in lua_arith.

since 0.1.0 · value: 12 (int)

Code for unary minus in lua_arith.

deprecatedlua_pcall
#define lua_pcall(L,n,r,f) lua_pcallk(L,(n),(r),(f),0,NULL)
since 0.1.0

Deprecated. Calls a function in protected mode.

deprecatedlua_pcallk
int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k)
since 0.1.0

Deprecated. Use CPROTECT_BEGIN/CPROTECT_END macros instead.

#define lua_pop(L,n) lua_settop(L, -(n)-1)
since 0.1.0

Pops n elements from the stack.

void lua_pushboolean (lua_State *L, int b)
since 0.1.0
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n)
since 0.1.0
#define lua_pushcfunction(L,f) lua_pushcclosure(L,(f),0)
since 0.1.0

Pushes a C function onto the stack (macro for lua_pushcclosure with 0 upvalues).

void lua_pushenum (lua_State *L, int npairs)
since 0.1.0
const char *lua_pushexternalstring (lua_State *L, const char *s, size_t len, lua_Alloc falloc, void *ud)
since 0.1.0
const char *lua_pushfstring (lua_State *L, const char *fmt, ...)
since 0.1.0
#define lua_pushglobaltable(L) ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
since 0.1.0

Pushes the global environment table onto the stack.

void lua_pushinteger (lua_State *L, lua_Integer n)
since 0.1.0
void lua_pushlightuserdata (lua_State *L, void *p)
since 0.1.0
#define lua_pushliteral(L,s) lua_pushstring(L, "" s)
since 0.1.0

Pushes a literal string onto the stack.

const char *lua_pushlstring (lua_State *L, const char *s, size_t len)
since 0.1.0
void lua_pushnil (lua_State *L)
since 0.1.0
void lua_pushnumber (lua_State *L, lua_Number n)
since 0.1.0
const char *lua_pushstring (lua_State *L, const char *s)
since 0.1.0
int lua_pushthread (lua_State *L)
since 0.1.0
void lua_pushvalue (lua_State *L, int idx)
since 0.1.0
const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp)
since 0.1.0
int lua_rawequal (lua_State *L, int idx1, int idx2)
since 0.1.0
int lua_rawget (lua_State *L, int idx)
since 0.1.0
int lua_rawgeti (lua_State *L, int idx, lua_Integer n)
since 0.1.0
int lua_rawgetp (lua_State *L, int idx, const void *p)
since 0.1.0
lua_Unsigned lua_rawlen (lua_State *L, int idx)
since 0.1.0
void lua_rawset (lua_State *L, int idx)
since 0.1.0
void lua_rawseti (lua_State *L, int idx, lua_Integer n)
since 0.1.0
void lua_rawsetp (lua_State *L, int idx, const void *p)
since 0.1.0
typedef const char *(*lua_Reader)(lua_State *L, void *ud, size_t *sz);
since 0.1.0

The reader function used by lua_load.

#define lua_register(L,n,f) (lua_pushcfunction(L,(f)), lua_setglobal(L,(n)))
since 0.1.0

Sets the C function f as the new value of global n.

since 0.1.0

Pseudo-index for the registry table.

#define lua_remove(L,idx) (lua_rotate(L,(idx),-1), lua_pop(L,1))
since 0.1.0

Removes the element at the given valid index, shifting down elements above.

#define lua_replace(L,idx) (lua_copy(L,-1,(idx)), lua_pop(L,1))
since 0.1.0

Moves the top element into the given valid index without shifting.

int lua_resume (lua_State *L, lua_State *from, int narg, int *nres)
since 0.1.0
since 0.1.0 · value: 2 (int)

Registry index for the global environment table.

since 0.1.0 · value: 3 (int)

Registry index for the main thread.

void lua_rotate (lua_State *L, int idx, int n)
since 0.1.0
void lua_setallocf (lua_State *L, lua_Alloc f, void *ud)
since 0.1.0
void lua_setfield (lua_State *L, int idx, const char *k)
since 0.1.0
void lua_setglobal (lua_State *L, const char *name)
since 0.1.0
void lua_sethook (lua_State *L, lua_Hook func, int mask, int count)
since 0.1.0
void lua_seti (lua_State *L, int idx, lua_Integer n)
since 0.1.0
int lua_setiuservalue (lua_State *L, int idx, int n)
since 0.1.0
const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n)
since 0.1.0
int lua_setmetatable (lua_State *L, int objindex)
since 0.1.0
void lua_settable (lua_State *L, int idx)
since 0.1.0
void lua_settop (lua_State *L, int idx)
since 0.1.0
const char *lua_setupvalue (lua_State *L, int funcindex, int n)
since 0.1.0
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
since 0.1.0

Compatibility macro. Sets the first user value of a userdata.

void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud)
since 0.1.0
typedef struct lua_State lua_State;
since 0.1.0

An opaque structure that points to a thread and indirectly to the whole state of a Lua interpreter.

int lua_status (lua_State *L)
since 0.1.0
size_t lua_stringtonumber (lua_State *L, const char *s)
since 0.1.0
since 0.1.0 · value: 1 (int)

Tag for boolean values.

since 0.1.0 · value: 9 (int)

Tag for enum values.

since 0.1.0 · value: 6 (int)

Tag for function values.

since 0.1.0 · value: 2 (int)

Tag for light userdata.

since 0.1.0 · value: 0 (int)

Tag for nil values.

since 0.1.0 · value: -1 (int)

Tag for no value.

since 0.1.0 · value: 3 (int)

Tag for number values.

int lua_toboolean (lua_State *L, int idx)
since 0.1.0
lua_CFunction lua_tocfunction (lua_State *L, int idx)
since 0.1.0
void lua_toclose (lua_State *L, int idx)
since 0.1.0
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
since 0.1.0

Converts the value at the given index to a lua_Integer.

lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum)
since 0.1.0
const char *lua_tolstring (lua_State *L, int idx, size_t *len)
since 0.1.0
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
since 0.1.0

Converts the value at the given index to a lua_Number.

lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum)
since 0.1.0
const void *lua_topointer (lua_State *L, int idx)
since 0.1.0
#define lua_tostring(L,i) lua_tolstring(L,(i),NULL)
since 0.1.0

Equivalent to lua_tolstring with len equal to NULL.

lua_State *lua_tothread (lua_State *L, int idx)
since 0.1.0
void *lua_touserdata (lua_State *L, int idx)
since 0.1.0
since 0.1.0 · value: 4 (int)

Tag for string values.

since 0.1.0 · value: 5 (int)

Tag for table values.

since 0.1.0 · value: 8 (int)

Tag for thread (coroutine) values.

since 0.1.0 · value: 7 (int)

Tag for full userdata.

since 0.1.0 · value: 10 (int)

Tag for vector values.

int lua_type (lua_State *L, int idx)
since 0.1.0
const char *lua_typename (lua_State *L, int tp)
since 0.1.0
typedef unsigned long long lua_Unsigned;
since 0.1.0

The unsigned version of lua_Integer.

void *lua_upvalueid (lua_State *L, int fidx, int n)
since 0.1.0
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
since 0.1.0

Returns the pseudo-index for the i-th upvalue of a C closure.

void lua_upvaluejoin (lua_State *L, int fidx1, int n1, int fidx2, int n2)
since 0.1.0
lua_Number lua_version (lua_State *L)
since 0.1.0
typedef void (*lua_WarnFunction)(void *ud, const char *msg, int tocont);
since 0.1.0

The type of warning functions.

void lua_warning (lua_State *L, const char *msg, int tocont)
since 0.1.0
typedef int (*lua_Writer)(lua_State *L, const void *p, size_t sz, void *ud);
since 0.1.0

The writer function used by lua_dump.

void lua_xmove (lua_State *from, lua_State *to, int n)
since 0.1.0
#define lua_yield(L,n) lua_yieldk(L,(n),0,NULL)
since 0.1.0

Yields a coroutine (macro for lua_yieldk with no continuation).

int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k)
since 0.1.0

Auxiliary C API

since 0.1.0 · value: 6 (int)

Error code for file-related errors in luaL_loadfile.

since 0.1.0

Metatable name for file handles.

since 0.1.0 · value: -2 (int)

Special reference value representing no reference.

since 0.1.0 · value: -1 (int)

Special reference value representing a reference to nil.

#define luaL_addchar(B,c)
since 0.1.0

Adds the byte c to the buffer B.

void luaL_addgsub (luaL_Buffer *b, const char *s, const char *p, const char *r)
since 0.1.0
void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l)
since 0.1.0
#define luaL_addsize(B,s) ((B)->n += (s))
since 0.1.0

Adds to the buffer a string of length s previously copied to the buffer area.

void luaL_addstring (luaL_Buffer *B, const char *s)
since 0.1.0
void luaL_addvalue (luaL_Buffer *B)
since 0.1.0
void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize)
since 0.1.0
#define luaL_argcheck(L,cond,arg,extramsg)
since 0.1.0

Checks whether cond is true. If not, raises an argument error.

int luaL_argerror (lua_State *L, int arg, const char *extramsg)
since 0.1.0
#define luaL_argexpected(L,cond,arg,tname)
since 0.1.0

Checks whether cond is true. If not, raises a type error.

#define luaL_buffaddr(bf) ((bf)->b)
since 0.1.0

Returns the address of the buffer content.

struct luaL_Buffer { char *b; size_t size; size_t n; lua_State *L; };
since 0.1.0

Type for a string buffer. A string buffer allows C code to build Lua strings piecemeal.

since 0.1.0

The initial buffer size used by the buffer system.

void luaL_buffinit (lua_State *L, luaL_Buffer *B)
since 0.1.0
char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz)
since 0.1.0
#define luaL_bufflen(bf) ((bf)->n)
since 0.1.0

Returns the current length of the buffer content.

#define luaL_buffsub(B,s) ((B)->n -= (s))
since 0.1.0

Removes s bytes from the buffer.

int luaL_callmeta (lua_State *L, int obj, const char *e)
since 0.1.0
void luaL_checkany (lua_State *L, int arg)
since 0.1.0
lua_Integer luaL_checkinteger (lua_State *L, int arg)
since 0.1.0
const char *luaL_checklstring (lua_State *L, int arg, size_t *l)
since 0.1.0
lua_Number luaL_checknumber (lua_State *L, int arg)
since 0.1.0
int luaL_checkoption (lua_State *L, int arg, const char *def, const char *const lst[])
since 0.1.0
void luaL_checkstack (lua_State *L, int sz, const char *msg)
since 0.1.0
#define luaL_checkstring(L,n) (luaL_checklstring(L,(n),NULL))
since 0.1.0

Checks whether the function argument n is a string and returns it.

void luaL_checktype (lua_State *L, int arg, int t)
since 0.1.0
void *luaL_checkudata (lua_State *L, int ud, const char *tname)
since 0.1.0
#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
since 0.1.0

Checks that the code making the call and the Lua library being called are using the same version of Lua and compatible numeric types.

void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz)
since 0.1.0
#define luaL_dofile(L,fn) (luaL_loadfile(L,fn) || lua_pcall(L,0,LUA_MULTRET,0))
since 0.1.0

Loads and runs the given file.

#define luaL_dostring(L,s) (luaL_loadstring(L,s) || lua_pcall(L,0,LUA_MULTRET,0))
since 0.1.0

Loads and runs the given string.

int luaL_error (lua_State *L, const char *fmt, ...)
since 0.1.0
int luaL_execresult (lua_State *L, int stat)
since 0.1.0
int luaL_fileresult (lua_State *L, int stat, const char *fname)
since 0.1.0
int luaL_getmetafield (lua_State *L, int obj, const char *e)
since 0.1.0
#define luaL_getmetatable(L,n) (lua_getfield(L,LUA_REGISTRYINDEX,(n)))
since 0.1.0

Pushes onto the stack the metatable associated with the name n in the registry.

int luaL_getsubtable (lua_State *L, int idx, const char *fname)
since 0.1.0
const char *luaL_gsub (lua_State *L, const char *s, const char *p, const char *r)
since 0.1.0
lua_Integer luaL_len (lua_State *L, int idx)
since 0.1.0
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
since 0.1.0

Loads a buffer as a Lua chunk.

int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode)
since 0.1.0
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
since 0.1.0

Loads a file as a Lua chunk (macro for luaL_loadfilex with NULL mode).

int luaL_loadfilex (lua_State *L, const char *filename, const char *mode)
since 0.1.0
int luaL_loadstring (lua_State *L, const char *s)
since 0.1.0
unsigned luaL_makeseed (lua_State *L)
since 0.1.0
#define luaL_newlib(L,l) (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
since 0.1.0

Creates a new table and registers the functions in l into it.

#define luaL_newlibtable(L,l) lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
since 0.1.0

Creates a table with a size hint for the number of entries in l.

int luaL_newmetatable (lua_State *L, const char *tname)
since 0.1.0
lua_State *luaL_newstate (void)
since 0.1.0
since 0.1.0

Encodes the size of integers and floats for version checking.

lua_Integer luaL_optinteger (lua_State *L, int arg, lua_Integer def)
since 0.1.0
const char *luaL_optlstring (lua_State *L, int arg, const char *def, size_t *l)
since 0.1.0
lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def)
since 0.1.0
#define luaL_optstring(L,n,d) (luaL_optlstring(L,(n),(d),NULL))
since 0.1.0

If the function argument n is a string, returns it; otherwise returns d.

#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
since 0.1.0

Equivalent to luaL_prepbuffsize with LUAL_BUFFERSIZE.

char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz)
since 0.1.0
#define luaL_pushfail(L) lua_pushnil(L)
since 0.1.0

Pushes the fail value onto the stack.

void luaL_pushresult (luaL_Buffer *B)
since 0.1.0
void luaL_pushresultsize (luaL_Buffer *B, size_t sz)
since 0.1.0
int luaL_ref (lua_State *L, int t)
since 0.1.0
typedef struct luaL_Reg { const char *name; lua_CFunction func; } luaL_Reg;
since 0.1.0

Type for arrays of functions to be registered with luaL_setfuncs.

void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb)
since 0.1.0
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup)
since 0.1.0
void luaL_setmetatable (lua_State *L, const char *tname)
since 0.1.0
typedef struct luaL_Stream { FILE *f; lua_CFunction closef; } luaL_Stream;
since 0.1.0

The internal structure used by the standard I/O library for file handles.

void *luaL_testudata (lua_State *L, int ud, const char *tname)
since 0.1.0
const char *luaL_tolstring (lua_State *L, int idx, size_t *len)
since 0.1.0
void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level)
since 0.1.0
int luaL_typeerror (lua_State *L, int arg, const char *tname)
since 0.1.0
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
since 0.1.0

Returns the name of the type of the value at the given index.

void luaL_unref (lua_State *L, int t, int ref)
since 0.1.0
void luaL_where (lua_State *L, int lvl)
since 0.1.0