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 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 Function
s and UserData
.
Re-exports
Modules
- Re-exports most types with an extra
Lua*
prefix to prevent name clashes. - serde
serialize
(De)Serialization support using serde.
Macros
Structs
- Handle to an internal Lua userdata for any type that implements
UserData
. - A wrapper type for an immutably borrowed value from an app data container.
- A wrapper type for a mutably borrowed value from an app data container.
- AsyncThread
async
- Returned from
Lua::load
and is used to finalize loading and executing Lua main chunks. - Compiler
luau
Luau compiler - CoverageInfo
luau
Luau function coverage snapshot. - Contains information about currently executing Lua code.
- DeserializeOptions
serialize
A struct with options to change default deserializer behavior. - Handle to an internal Lua function.
- Contains information about a function.
- HookTriggersNon-
luau
Determines when a hook function will be called by Lua. - A “light” userdata value. Equivalent to an unmanaged raw pointer.
- Top level Lua struct which represents an instance of Lua VM.
- Controls Lua interpreter behavior such as Rust panics handling.
- Multiple Lua values used for both argument passing and also for multiple return values.
- OwnedAnyUserData
unstable
Owned handle to an internal Lua userdata. - OwnedFunction
unstable
Owned handle to an internal Lua function. - OwnedString
unstable
Owned handle to an internal Lua string. - OwnedTable
unstable
Owned handle to an internal Lua table. - OwnedThread
unstable
Owned handle to an internal Lua thread (coroutine). - An auto generated key into the Lua registry.
- Constructed by the
Lua::scope
method, allows temporarily creating Lua userdata and callbacks that are not required to be Send or ’static. - SerializeOptions
serialize
A struct with options to change default serializer behavior. - Flags describing the set of lua standard libraries to load.
- Handle to an internal Lua string.
- Handle to an internal Lua table.
- An iterator over the pairs of a Lua table.
- An iterator over the sequence part of a Lua table.
- Handle to an internal Lua thread (coroutine).
- Handle to a
UserData
metatable. - A wrapper type for an immutably borrowed value from a
AnyUserData
. - A wrapper type for a mutably borrowed value from a
AnyUserData
. - Handle to registry for userdata methods and metamethods.
- Wraps a variable number of
T
s. - Vector
luau
A Luau vector type. - A raw Lua state associated with a thread.
Enums
- Represents chunk mode (text or binary).
- Represents a specific event that triggered the hook.
- Error type returned by
mlua
methods. - Mode of the Lua garbage collector (GC).
- Kinds of metamethods that can be overridden.
- Status of a Lua thread (coroutine).
- A dynamically typed Lua value. The
String
,Table
,Function
,Thread
, andUserData
variants contain handle types into the internal Lua state. It is a logic error to mix handle types between separateLua
instances, and doing so will result in a panic. - VmState
luau
Type to set next Luau VM action after executing interrupt function.
Traits
- An extension trait for
AnyUserData
that provides a variety of convenient functionality. - Trait for types loadable by Lua and convertible to a
Chunk
- Trait for converting
std::error::Error
into LuaError
. - Trait for converting
std::result::Result
into LuaResult
. - Trait for types convertible from
Value
. - Trait for types that can be created from an arbitrary number of Lua values.
- Trait for types convertible to
Value
. - Trait for types convertible to any number of Lua values.
- LuaSerdeExt
serialize
Trait for serializing/deserializing Lua values using Serde. - An extension trait for
Table
s that provides a variety of convenient functionality. - Trait for custom userdata types.
- Field registry for
UserData
implementors. - Method registry for
UserData
implementors.
Type Aliases
- Type of Lua integer numbers.
- Type of Lua floating point numbers.
- A specialized
Result
type used bymlua
’s API. - Type for native C functions that can be passed to Lua
Attribute Macros
- lua_module
module
Registers Lua module entrypoint.