Safe, high-level Rust bindings for Lua 5.1-5.5, LuaJIT, and Luau with async/await support.
mlua is a set of Rust bindings for multiple Lua versions (5.1 through 5.5, LuaJIT, and Luau) that enables embedding Lua in Rust applications or writing Lua modules in Rust. It provides a safe, high-level API for seamless interoperability between Rust and Lua, supporting both standalone scripting and loadable module modes with a focus on safety and practicality.
Rust developers who need to embed Lua as a scripting engine in their applications or create native Lua modules in Rust for performance-critical extensions.
Developers choose mlua for its comprehensive multi-version Lua support, safety-first design that minimizes unsafe code, and flexible features like async/await integration and Serde serialization, making it suitable for production use.
High level Lua 5.5/5.4/5.3/5.2/5.1 (including LuaJIT) and Luau bindings to Rust with async/await support
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports Lua 5.1 through 5.5, LuaJIT, and Luau via feature flags, allowing flexibility across different Lua ecosystems without code changes.
Enables asynchronous Rust code to work with Lua coroutines using executors like Tokio or async-std, with provided examples for HTTP clients and servers.
Minimizes unsafe code by guarding Lua C API interactions with lua_pcall and handling panics across boundaries, as detailed in the Safety and Panic Handling sections.
Optional integration with serde simplifies serializing and deserializing Rust types to/from Lua values, reducing boilerplate for data exchange.
The 'vendored' feature builds Lua/LuaJIT from source, easing compilation and dependency management, especially for cross-platform projects.
Module mode requires platform-specific linker arguments (e.g., on macOS) and careful handling of Lua libraries, which can be error-prone for beginners.
The safe API adds overhead by wrapping Lua C API calls, which may impact latency-sensitive applications, as admitted in the Safety section.
Despite support for publishing to LuaRocks, the number of available Rust-written Lua modules is small compared to pure Lua libraries, limiting reuse.
Using external Lua runtimes in module mode can lead to unsafety due to unpredictable environments, as warned in the README, requiring extra caution.