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 ToLua 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 ToLuaMulti 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 implements serde::Serialize trait to support serializing Lua values
(including UserData) into Rust values.
Requires feature = "serialize".
Async/await support
The create_async_function allows creating non-blocking functions that returns Future.
Lua code with async capabilities can be executed by call_async family of functions or polling
AsyncThread using any runtime (eg. Tokio).
Requires feature = "async".
Send requirement
By default mlua is !Send. This can be changed by enabling feature = "send" that adds Send requirement
to Functions and UserData.
Re-exports
pub use crate::value::Nil;Modules
Lua* prefix to prevent name clashes.serializeMacros
Structs
UserData.asyncluauluauserializeluauLua::scope method, allows temporarily creating Lua userdata and
callbacks that are not required to be Send or ’static.serializeUserData metatable.Ts.Enums
mlua methods.String, Table, Function, Thread, and UserData
variants contain handle types into the internal Lua state. It is a logic error to mix handle
types between separate Lua instances, and doing so will result in a panic.luauTraits
ChunkValue.serializeTables that provides a variety of convenient functionality.Value.UserData implementors.UserData implementors.Type Definitions
Result type used by mlua’s API.Attribute Macros
module