Expand description
Rust bindings for the Luau C API.
§WIP
This crate is a work in progress and not yet complete. Bindings have not been written for all functions and documentation has not been written for all functions that have bindings.
luacodegen.h(native code generation) - Not bound, not documented.luacode.h(bytecode compilation) - Fully bound, partially documented.Require.h(require functionality) - Not bound, not documented.luaconf.h(VM configuration) - Fully bound, not documented.lualib.h(aux VM functionality) - Fully bound, not documented.lua.h(core VM functionality) - Fully bound, documented.
§Bindings
All types and functions in the Luau C API are bound with the exception of
types and functions that utilize ... or va_list. The Luau C API makes
extensive use of function-like macros, which have been closely reimplemented
in this crate as functions.
§Stability and versioning
Luau versions itself with an incrementing integer which increases with each
weekly release. As an example, at the time of writing, the latest Luau
version is 0.679.
This crate will track these versions, releasing a new version of the crate weekly to match the latest Luau versions. When a breaking change occurs, either in the Luau C API or in the bindings, a new major version will be released.
In summary, major versions will be released for breaking changes, minor versions track the latest Luau version, and patch versions will be used only for emergency bugfixes.
§Portability
Luau explicitly supports Windows, Linux, macOS, FreeBSD, iOS, and Android. As such, this crate explicitly supports those platforms as well. As of time of writing, the crate has only been tested on Linux. Please open an issue if you encounter any problems on other platforms.
Re-exports§
pub use lua_Status::*;pub use lua_CoStatus::*;pub use lua_Type::*;
Structs§
- luaL_
Reg - luaL_
Strbuf - lua_
Callbacks - TODO: Document this struct.
- lua_
Compile Options - Options to configure the Luau compiler with.
- lua_
Debug - TODO: Document this struct.
- lua_
State - Represents a Luau thread, stack, and environment. The main structure for interacting with the Luau VM.
Enums§
- lua_
CoStatus - The status codes of a coroutine.
- lua_
GCOp - Garbage collection operations that can be performed.
- lua_
Status - The status codes returned by the Luau VM.
- lua_
Type - The different types of Luau values.
Constants§
- LUAI_
MAXCALLS - LUAI_
MAXCCALLS - LUAI_
MAXCSTACK - LUA_
BITLIBNAME - LUA_
BUFFERLIBNAME - LUA_
BUFFERSIZE - LUA_
COLIBNAME - LUA_
DBLIBNAME - LUA_
ENVIRONINDEX - The pseudo-index for the environment table of the running function.
- LUA_
GLOBALSINDEX - The pseudo-index for the global environment table.
- LUA_
IDSIZE - LUA_
LUTAG_ LIMIT - LUA_
MATHLIBNAME - LUA_
MAXCAPTURES - LUA_
MEMORY_ CATEGORIES - LUA_
MINSTACK - LUA_
MINSTRTABSIZE - LUA_
MULTRET - Indicates that a call should return all values to the caller.
- LUA_
NOREF - A placeholder value that is unique from any created reference.
- LUA_
OSLIBNAME - LUA_
REFNIL - A reference that is used to refer to a nil value.
- LUA_
REGISTRYINDEX - The pseudo-index for the registry.
- LUA_
SIZECLASSES - LUA_
STRLIBNAME - LUA_
TABLIBNAME - LUA_
UTAG_ LIMIT - LUA_
UTF8LIBNAME - LUA_
VECLIBNAME - LUA_
VECTOR_ SIZE
Functions§
- luaL_
addchar ⚠ - luaL_
addlstring ⚠ - luaL_
addstring ⚠ - luaL_
addvalue ⚠ - luaL_
addvalueany ⚠ - luaL_
argcheck ⚠ - luaL_
argerror ⚠ - luaL_
argerrorL ⚠ - luaL_
argexpected ⚠ - luaL_
buffinit ⚠ - luaL_
buffinitsize ⚠ - luaL_
callmeta ⚠ - luaL_
callyieldable ⚠ - luaL_
checkany ⚠ - luaL_
checkboolean ⚠ - luaL_
checkbuffer ⚠ - luaL_
checkinteger ⚠ - luaL_
checklstring ⚠ - luaL_
checknumber ⚠ - luaL_
checkoption ⚠ - luaL_
checkstack ⚠ - luaL_
checkstring ⚠ - luaL_
checktype ⚠ - luaL_
checkudata ⚠ - luaL_
checkunsigned ⚠ - luaL_
checkvector ⚠ - luaL_
findtable ⚠ - luaL_
getmetafield ⚠ - luaL_
getmetatable ⚠ - luaL_
newmetatable ⚠ - luaL_
newstate ⚠ - luaL_
openlibs ⚠ - luaL_
opt ⚠ - luaL_
optboolean ⚠ - luaL_
optinteger ⚠ - luaL_
optlstring ⚠ - luaL_
optnumber ⚠ - luaL_
optstring ⚠ - luaL_
optunsigned ⚠ - luaL_
optvector ⚠ - luaL_
prepbuffsize ⚠ - luaL_
pushresult ⚠ - luaL_
pushresultsize ⚠ - luaL_
register ⚠ - luaL_
sandbox ⚠ - luaL_
sandboxthread ⚠ - luaL_
tolstring ⚠ - luaL_
typeerror ⚠ - luaL_
typeerrorL ⚠ - luaL_
typename ⚠ - luaL_
where ⚠ - lua_
absindex ⚠ - Transforms a stack index into an index that is not relative to the top of the stack.
- lua_
break ⚠ - TODO: Document this function.
- lua_
breakpoint ⚠ - TODO: Document this function.
- lua_
call ⚠ - Calls a function on the stack, with the given number of arguments, and the given number of results.
- lua_
callbacks ⚠ - TODO: Document this function.
- lua_
checkstack ⚠ - Attempts to make space on the stack for at least
nmore values. - lua_
cleartable ⚠ - Clears the table at the given index.
- lua_
clock ⚠ - Returns a high-precision timestamp in seconds.
- lua_
clonefunction ⚠ - Clones the function at the given index and pushes it onto the stack.
- lua_
clonetable ⚠ - Clones the table at the given index and pushes it onto the stack.
- lua_
close ⚠ - Closes the passed
lua_State. - lua_
concat ⚠ - Concatenates
nvalues from the stack into a string. - lua_
costatus ⚠ - Returns the status of the given coroutine.
- lua_
cpcall ⚠ - Calls a protected C function with a single light userdata argument.
- lua_
createtable ⚠ - Creates a new table of the given size and pushes it onto the stack.
- lua_
debugtrace ⚠ - TODO: Document this function.
- lua_
encodepointer ⚠ - Encodes a pointer such that it remains unique but no longer points to the original location.
- lua_
equal ⚠ - Compares the values at the two indices for equality.
- lua_
error ⚠ - Throws an error.
- lua_gc⚠
- Performs a garbage collection operation.
- lua_
getallocf ⚠ - Returns the memory allocation function of the state.
- lua_
getargument ⚠ - TODO: Document this function.
- lua_
getcoverage ⚠ - TODO: Document this function.
- lua_
getfenv ⚠ - Gets the environment of the value at the given index and pushes it onto the top of the stack.
- lua_
getfield ⚠ - Indexes a table at the given index with the given string key and pushes the value onto the stack.
- lua_
getglobal ⚠ - Gets a global variable with the given name and pushes it onto the stack.
- lua_
getinfo ⚠ - TODO: Document this function.
- lua_
getlightuserdataname ⚠ - Gets the name of a light userdata tag.
- lua_
getlocal ⚠ - TODO: Document this function.
- lua_
getmetatable ⚠ - Gets and pushes the metatable of the value at the given index onto the top of the stack.
- lua_
getreadonly ⚠ - Gets the readonly status of the table at the given index.
- lua_
getref ⚠ - Pushes the value of the given reference onto the stack.
- lua_
gettable ⚠ - Indexes a table at the given index with the key at the top of the stack and pushes the value onto the stack.
- lua_
getthreaddata ⚠ - Returns the thread-data pointer of the given thread.
- lua_
gettop ⚠ - Returns the number of items on the stack.
- lua_
getupvalue ⚠ - TODO: Document this function.
- lua_
getuserdatadtor ⚠ - Gets the destructor of a userdata tag.
- lua_
getuserdatametatable ⚠ - Gets the metatable that userdata with the given tag will have when
created with
lua_newuserdatataggedwithmetatable. - lua_
insert ⚠ - Moves the value at the given index to the top of the stack.
- lua_
isLfunction ⚠ - Does the given index contain a value of type function which is a Luau function.
- lua_
isboolean ⚠ - Returns if the value at the given index is a boolean.
- lua_
isbuffer ⚠ - Returns if the value at the given index is a buffer.
- lua_
iscfunction ⚠ - Does the given index contain a value of type function which is a C function.
- lua_
isfunction ⚠ - Returns if the value at the given index is a function.
- lua_
islightuserdata ⚠ - Returns if the value at the given index is a light userdata.
- lua_
isnil ⚠ - Returns if the value at the given index is nil.
- lua_
isnone ⚠ - Returns if the value at the given index is none.
- lua_
isnoneornil ⚠ - Returns if the value at the given index is none or nil.
- lua_
isnumber ⚠ - Does the given index contain a value of type number.
- lua_
ispseudo - Checks if the given index is a pseudo-index.
- lua_
isstring ⚠ - Does the given index contain a value of type string.
- lua_
istable ⚠ - Returns if the value at the given index is a table.
- lua_
isthread ⚠ - Returns if the value at the given index is a thread.
- lua_
isthreadreset ⚠ - TODO: Document this function.
- lua_
isuserdata ⚠ - Does the given index contain a value of type userdata.
- lua_
isvector ⚠ - Returns if the value at the given index is a vector.
- lua_
isyieldable ⚠ - Returns if the thread is yieldable or not.
- lua_
lessthan ⚠ - Compares the values at the two indices for less than.
- lua_
lightuserdatatag ⚠ - Returns the tag of the light userdata at the given index.
- lua_
mainthread ⚠ - Returns the main thread of the given state.
- lua_
namecallatom ⚠ - Returns the value of the namecall method string as well as its atom.
- lua_
newbuffer ⚠ - Pushes a new buffer onto the top of the stack.
- lua_
newstate ⚠ - Creates a new
lua_State. - lua_
newtable ⚠ - Creates a new table and pushes it onto the stack.
- lua_
newthread ⚠ - Creates a new thread.
- lua_
newuserdata ⚠ - Creates a new userdata of the given size and pushes it onto the stack.
- lua_
newuserdatadtor ⚠ - Pushes a new userdata with a destructor onto the top of the stack.
- lua_
newuserdatatagged ⚠ - Pushes a new userdata with a tag onto the top of the stack.
- lua_
newuserdatataggedwithmetatable ⚠ - Pushes a new userdata with a tag and a metatable onto the top of the stack.
- lua_
next ⚠ - Produces the next key and value pair from a table given the previous key.
- lua_
objlen ⚠ - Returns the length of the value at the given index.
- lua_
pcall ⚠ - Calls a protected function on the stack, with the given number of arguments, and the given number of results.
- lua_pop⚠
- Pops
nnumber of values from the stack. - lua_
pushboolean ⚠ - Pushes a boolean onto the top of the stack.
- lua_
pushcclosure ⚠ - Pushes a C closure onto the stack.
- lua_
pushcclosurek ⚠ - Pushes a C function with upvalues and continuation onto the top of the stack.
- lua_
pushcfunction ⚠ - Pushes a C function onto the stack.
- lua_
pushinteger ⚠ - Pushes an integer onto the top of the stack.
- lua_
pushlightuserdata ⚠ - Pushes a light userdata onto the stack.
- lua_
pushlightuserdatatagged ⚠ - Pushes a light userdata with a tag onto the top of the stack.
- lua_
pushliteral ⚠ - Pushes a literal string onto the stack.
- lua_
pushlstring ⚠ - Pushes a string with a length onto the top of the stack.
- lua_
pushnil ⚠ - Pushes a nil value onto the top of the stack.
- lua_
pushnumber ⚠ - Pushes a number onto the top of the stack.
- lua_
pushstring ⚠ - Pushes a string onto the top of the stack.
- lua_
pushthread ⚠ - Pushes the thread onto the top of its own stack.
- lua_
pushunsigned ⚠ - Pushes an unsigned integer onto the top of the stack.
- lua_
pushvalue ⚠ - Pushes a value onto the stack.
- lua_
pushvector ⚠ - Pushes a vector onto the top of the stack.
- lua_
rawcheckstack ⚠ - TODO: Document this function.
- lua_
rawequal ⚠ - Compares the values at the two indices for raw equality.
- lua_
rawget ⚠ - Raw-indexes a table at the given index with the key at the top of the stack and pushes the value onto the stack.
- lua_
rawgetfield ⚠ - Raw-indexes a table at the given index with the given string key and pushes the value onto the stack.
- lua_
rawgeti ⚠ - Raw-indexes a table at the given index with the given integer key and pushes the value onto the stack.
- lua_
rawiter ⚠ - Produces the next key and value pair from a table given the previous iteration index.
- lua_
rawset ⚠ - Raw-sets a value in a table at the given index with the key at the top of the stack.
- lua_
rawsetfield ⚠ - Raw-sets a value in a table at the given index with the given string key.
- lua_
rawseti ⚠ - Raw-sets a value in a table at the given index with the given integer key.
- lua_ref⚠
- Creates a reference to the value at the given index.
- lua_
remove ⚠ - Removes the value at the given index from the stack.
- lua_
replace ⚠ - Replaces the given index with the value at the top of the stack.
- lua_
resetthread ⚠ - TODO: Document this function.
- lua_
resume ⚠ - Resumes a thread with the given number of arguments.
- lua_
resumeerror ⚠ - Resumes a thread with an error.
- lua_
setfenv ⚠ - Sets the environment of the value at the given index to the value at the top of the stack.
- lua_
setfield ⚠ - Sets a value in a table at the given index with the given string key.
- lua_
setglobal ⚠ - Sets a global variable with the given name.
- lua_
setlightuserdataname ⚠ - Sets the name of a light userdata tag.
- lua_
setlocal ⚠ - TODO: Document this function.
- lua_
setmemcat ⚠ - Sets the memory category of the thread.
- lua_
setmetatable ⚠ - Sets the metatable of the value at the given index to the value at the top of the stack.
- lua_
setreadonly ⚠ - Sets the readonly status of the table at the given index.
- lua_
setsafeenv ⚠ - Sets the safe environment status of the table at the given index.
- lua_
settable ⚠ - Sets a value in a table at the given index with the key at the top of stack.
- lua_
setthreaddata ⚠ - Sets the thread-data pointer of the given thread.
- lua_
settop ⚠ - Sets the top of the stack to the given index.
- lua_
setupvalue ⚠ - TODO: Document this function.
- lua_
setuserdatadtor ⚠ - Sets the destructor of a userdata tag.
- lua_
setuserdatametatable ⚠ - Sets the metatable that userdata with the given tag will have when
created with
lua_newuserdatataggedwithmetatable. - lua_
setuserdatatag ⚠ - Sets the tag of a userdata at the given index.
- lua_
singlestep ⚠ - TODO: Document this function.
- lua_
stackdepth ⚠ - Returns the stack depth, or the number of calls on the stack.
- lua_
status ⚠ - Returns the status of the thread.
- lua_
strlen ⚠ - Returns the length of the string at the given index in bytes.
- lua_
toboolean ⚠ - Returns the truthiness of the value at the given index.
- lua_
tobuffer ⚠ - Returns the buffer at the given index.
- lua_
tocfunction ⚠ - Returns a pointer to the C function at the given index.
- lua_
tointeger ⚠ - Attempts to convert the value at the given index to an integer, and returns it.
- lua_
tointegerx ⚠ - Attempts to convert the value at the given index to an integer.
- lua_
tolightuserdata ⚠ - Returns the pointer of the light userdata at the given index.
- lua_
tolightuserdatatagged ⚠ - Returns the pointer to the light userdata at the given index if it has the given tag.
- lua_
tolstring ⚠ - Attempts to convert the value at the given index to a string and returns its value and length.
- lua_
tolstringatom ⚠ - Returns the value of the string at the given index as well as its atom and length.
- lua_
tonumber ⚠ - Attempts to convert the value at the given index to a number, and returns it.
- lua_
tonumberx ⚠ - Attempts to convert the value at the given index to a number.
- lua_
topointer ⚠ - Returns the pointer of the value at the given index.
- lua_
tostring ⚠ - Attempts to convert the value at the given index to a string, and return it.
- lua_
tostringatom ⚠ - Returns the value of the string at the given index as well as its atom.
- lua_
totalbytes ⚠ - Reads the number of bytes allocated to a given memory category.
- lua_
tothread ⚠ - Returns the thread at the given index.
- lua_
tounsigned ⚠ - Attempts to convert the value at the given index to an unsigned integer, and returns it.
- lua_
tounsignedx ⚠ - Attempts to convert the value at the given index to an unsigned integer.
- lua_
touserdata ⚠ - Returns the pointer to the userdata at the given index.
- lua_
touserdatatagged ⚠ - Returns the pointer to the userdata at the given index if it has the given tag.
- lua_
tovector ⚠ - Returns the value of the vector at the given index.
- lua_
type ⚠ - Returns the type of the value at the given index.
- lua_
typename ⚠ - Returns the name of the given type.
- lua_
unref ⚠ - Releases a reference to a value.
- lua_
upvalueindex - Produces the pseudo-indicies for upvalues of C functions.
- lua_
userdatatag ⚠ - Returns the tag of the userdata at the given index.
- lua_
xmove ⚠ - Moves values from the top of one stack to another stack.
- lua_
xpush ⚠ - Pushes a value from an index of one stack onto another stack.
- lua_
yield ⚠ - Yields the thread with the given number of results.
- luaopen_
base ⚠ - luaopen_
bit32 ⚠ - luaopen_
buffer ⚠ - luaopen_
coroutine ⚠ - luaopen_
debug ⚠ - luaopen_
math ⚠ - luaopen_
os ⚠ - luaopen_
string ⚠ - luaopen_
table ⚠ - luaopen_
utf8 ⚠ - luaopen_
vector ⚠ - luau_
compile ⚠ - Compiles the given source code into Luau bytecode.
- luau_
load ⚠ - Pushes a function constructed from bytecode onto the top of the stack.
- luau_
set_ ⚠compile_ constant_ boolean - Sets the given compile constant to a boolean value.
- luau_
set_ ⚠compile_ constant_ nil - Sets the given compile constant to
nil. - luau_
set_ ⚠compile_ constant_ number - Sets the given compile constant to a number value.
- luau_
set_ ⚠compile_ constant_ string - Sets the given compile constant to a string value.
- luau_
set_ ⚠compile_ constant_ vector - Sets the given compile constant to a vector value. This function always takes four components, but when loaded into a Luau VM the last component will be ignored if the VM is in 3-wide mode.
Type Aliases§
- lua_
Alloc - The type of the memory allocator function used by Luau’s VM.
- lua_
CFunction - The type of a C function that can be called from Luau.
- lua_
Compile Constant - A constant that can be configured during compilation to enable constant folding and other optimizations.
- lua_
Continuation - The type of a continuation function that can be called from Luau.
- lua_
Coverage - TODO: Document this type.
- lua_
Destructor - The type of destructor functions for userdata.
- lua_
Hook - TODO: Document this type.
- lua_
Integer - The type of Luau integers.
- lua_
Library Member Constant Callback - Allows the configuration of a constant in a library at compile time. This enables the compiler to optimize code with constant folding and other optimizations.
- lua_
Library Member Type Callback - A callback to retrieve the type of a member in a library, which is used to provide type information during native codegen.
- lua_
Number - The type of Luau numbers.
- lua_
Unsigned - The type of Luau unsigned integers.