Crate lu_sys

Source
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_CompileOptions
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 n more 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 n values from the stack into a string.
lua_costatus
Returns the status of the given coroutine.
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 n number 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_CompileConstant
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_LibraryMemberConstantCallback
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_LibraryMemberTypeCallback
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.