mlua exposes Lua 5.1 through 5.5, LuaJIT, and Luau to Rust with optional async, serde, and native module support.
Overview
mlua is a Rust crate that wraps the Lua C API with a higher-level, safety-oriented interface. It grew from rlua and targets embedders who want scripting inside Rust applications or who want to ship Lua modules written in Rust.
Feature flags choose the Lua language version, optional vendored static builds, async integration with executors such as tokio or async-std, serde serialization for values, procedural macros, and module mode for loadable cdylib plugins. Luau support includes an optional sandbox helper for untrusted scripts.
Standalone mode embeds a configured Lua runtime in your binary. Module mode produces shared libraries that Lua can require, with platform-specific linker notes for macOS, Linux, and Windows. WebAssembly targets are documented for wasm32 with a WASI C runtime.
The project stresses guarding Lua errors and panics across the FFI boundary, though maintainers note that absolute safety cannot be guaranteed when using the underlying C API. Tests run on Windows, macOS, and Linux in CI.
Key features
- Multiple Lua version backends
- Luau and LuaJIT support
- Async await integration
- Serde value serialization
- Vendored Lua builds
- Rust-authored Lua modules
- Standalone embed mode
- Luau sandbox helper
Use cases
- Embedding Lua in Rust apps
- Game or tool scripting
- Native Lua extension modules
- Async scripted network services
- WASM-hosted Lua runtimes