Expand description
§High-level bindings to Lua
The mlua crate provides safe high-level bindings to the Lua programming language.
§The Lua object
The main type exported by this library is the Lua struct. In addition to methods for
executing Lua chunks or evaluating Lua expressions, it provides methods for creating Lua
values and accessing the table of globals.
§Converting data
The IntoLua and FromLua traits allow conversion from Rust types to Lua values and vice
versa. They are implemented for many data structures found in Rust’s standard library.
For more general conversions, the IntoLuaMulti and FromLuaMulti traits allow converting
between Rust types and any number of Lua values.
Most code in mlua is generic over implementors of those traits, so in most places the normal
Rust data structures are accepted without having to write any boilerplate.
§Custom Userdata
The UserData trait can be implemented by user-defined types to make them available to Lua.
Methods and operators to be used from Lua can be added using the UserDataMethods API.
Fields are supported using the UserDataFields API.
§Serde support
The LuaSerdeExt trait implemented for Lua allows conversion from Rust types to Lua
values and vice versa using serde. Any user defined data type that implements
serde::Serialize or serde::Deserialize can be converted.
For convenience, additional functionality to handle NULL values and arrays is provided.
The Value enum and other types implement serde::Serialize trait to support serializing
Lua values into Rust values.
Requires feature = "serde".
§Async/await support
The Lua::create_async_function allows creating non-blocking functions that returns
Future. Lua code with async capabilities can be executed by Function::call_async family
of functions or polling AsyncThread using any runtime (eg. Tokio).
Requires feature = "async".
§Send and Sync support
By default mlua is !Send. This can be changed by enabling feature = "send" that adds
Send requirement to Rust functions and UserData types.
In this case Lua object and their types can be send or used from other threads. Internally
access to Lua VM is synchronized using a reentrant mutex that can be locked many times within
the same thread.
Re-exports§
Modules§
- prelude
- Re-exports most types with an extra Lua*prefix to prevent name clashes.
- serdeserde
- (De)Serialization support using serde.
Macros§
Structs§
- AnyUserData 
- Handle to an internal Lua userdata for any type that implements UserData.
- AppDataRef 
- A wrapper type for an immutably borrowed value from an app data container.
- AppDataRefMut 
- A wrapper type for a mutably borrowed value from an app data container.
- AsyncThread async
- Thread (coroutine) representation as an async FutureorStream.
- BString
- A wrapper for Vec<u8>that provides convenient string oriented trait impls.
- BorrowedBytes 
- A borrowed byte slice (&[u8]) that holds a strong reference to the Lua state.
- BorrowedStr 
- A borrowed string (&str) that holds a strong reference to the Lua state.
- Bufferluau
- A Luau buffer type.
- Chunk
- Returned from Lua::loadand is used to finalize loading and executing Lua main chunks.
- Compilerluau
- Luau compiler
- CoverageInfo luau
- Luau function coverage snapshot.
- Debug
- Contains information about currently executing Lua code.
- DebugNames 
- DebugSource 
- DebugStack 
- DeserializeOptions serde
- A struct with options to change default deserializer behavior.
- Function
- Handle to an internal Lua function.
- FunctionInfo 
- Contains information about a function.
- HookTriggers 
- Determines when a hook function will be called by Lua.
- LightUser Data 
- A “light” userdata value. Equivalent to an unmanaged raw pointer.
- Lua
- Top level Lua struct which represents an instance of Lua VM.
- LuaOptions
- Controls Lua interpreter behavior such as Rust panics handling.
- MultiValue 
- Multiple Lua values used for both argument passing and also for multiple return values.
- RegistryKey 
- An auto generated key into the Lua registry.
- Scope
- Constructed by the Lua::scopemethod, allows temporarily creating Lua userdata and callbacks that are not required to beSendor'static.
- SerializeOptions serde
- A struct with options to change default serializer behavior.
- StdLib
- Flags describing the set of lua standard libraries to load.
- String
- Handle to an internal Lua string.
- Table
- Handle to an internal Lua table.
- TablePairs 
- An iterator over the pairs of a Lua table.
- TableSequence 
- An iterator over the sequence part of a Lua table.
- Thread
- Handle to an internal Lua thread (coroutine).
- UserData Metatable 
- Handle to a AnyUserDatametatable.
- UserData Ref 
- A wrapper type for a userdata value that provides read access.
- UserData RefMut 
- A wrapper type for a userdata value that provides read and write access.
- UserData Registry 
- Handle to registry for userdata methods and metamethods.
- Variadic
- Wraps a variable number of Ts.
- Vectorluau
- A Luau vector type.
- WeakLua
- Weak reference to Lua instance.
- lua_State 
- A raw Lua state associated with a thread.
Enums§
- ChunkMode 
- Represents chunk mode (text or binary).
- CompileConstant luau
- Represents a constant value that can be used by Luau compiler.
- DebugEvent 
- Represents a specific event that triggered the hook.
- Either
- The enum Eitherwith variantsLeftandRightis a general purpose sum type with two cases.
- Error
- Error type returned by mluamethods.
- GCMode
- Mode of the Lua garbage collector (GC).
- MetaMethod 
- Kinds of metamethods that can be overridden.
- NavigateError luau
- An error that can occur during navigation in the Luau requiresystem.
- ThreadStatus 
- Status of a Lua thread (coroutine).
- Value
- A dynamically typed Lua value.
- VmState
- Type to set next Lua VM action after executing interrupt or hook function.
Traits§
- AsChunk
- Trait for types loadable by Lua and convertible to a Chunk
- ErrorContext 
- Provides the contextmethod forErrorandResult<T, Error>.
- ExternalError 
- Trait for converting std::error::Errorinto LuaError.
- ExternalResult 
- Trait for converting std::result::Resultinto LuaResult.
- FromLua
- Trait for types convertible from Value.
- FromLuaMulti 
- Trait for types that can be created from an arbitrary number of Lua values.
- IntoLua
- Trait for types convertible to Value.
- IntoLuaMulti 
- Trait for types convertible to any number of Lua values.
- LuaNativeAsync Fn async
- A trait for types that returns a future and can be used as Lua functions.
- LuaNativeFn 
- A trait for types that can be used as Lua functions.
- LuaNativeFnMut 
- A trait for types with mutable state that can be used as Lua functions.
- LuaSerdeExt serde
- Trait for serializing/deserializing Lua values using Serde.
- MaybeSend 
- A trait that adds Sendrequirement ifsendfeature is enabled.
- ObjectLike 
- A trait for types that can be used as Lua objects (usually table and userdata).
- Requireluau
- A trait for handling modules loading and navigation in the Luau requiresystem.
- UserData 
- Trait for custom userdata types.
- UserData Fields 
- Field registry for UserDataimplementors.
- UserData Methods 
- Method registry for UserDataimplementors.
Type Aliases§
- Integer
- Type of Lua integer numbers.
- Number
- Type of Lua floating point numbers.
- Result
- A specialized Resulttype used bymlua’s API.
- lua_CFunction 
- Type for native C functions that can be passed to Lua
Attribute Macros§
- lua_module module
- Registers Lua module entrypoint.