luars
luars is an embeddable pure Rust Lua 5.5 runtime crate. It includes the compiler, VM, GC, standard library, and a high-level host API built around Lua.
If you want the repository-level overview, including examples and companion crates, start with ../../README.md. This README focuses on the crate surface that application code should use directly.
Installation
[]
= "0.18"
Optional features:
[]
= { = "0.18", = ["serde", "sandbox"] }
Quick Start
use ;
High-Level Workflow
Execute code
lua.load.exec?;
let answer: i64 = lua.load.eval?;
let pair: = lua.load.eval_multi?;
Call Lua globals
lua.load
.exec?;
let text: String = lua.call_global1?;
Register Rust functions
lua.register_function?;
Exchange tables and globals
let config = lua.create_table_from?;
lua.globals.set?;
let globals = lua.globals;
let host: String = globals.get?.get?;
assert_eq!;
Expose Rust types as userdata
use ;
lua.?;
let count: i64 = lua
.load
.eval?;
assert_eq!;
Use scoped borrowed values
let result: String = lua.scope?;
assert_eq!;
Async And Sandbox
The high-level API supports both typed async callbacks and async execution entry points:
lua.register_async_function?;
let result: i64 = lua.load.eval_async.await?;
assert_eq!;
You can also drive existing Lua functions asynchronously with call_async(), call_async1(), call_async_global(), and call_async_global1().
When the sandbox feature is enabled, the same high-level surface exposes isolated execution helpers:
use SandboxConfig;
let mut sandbox = default;
lua.sandbox_insert_global?;
let answer: i64 = lua.eval_sandboxed?;
assert_eq!;
For more detail, see ../../docs/Async.md.
Feature Flags
| Feature | Description |
|---|---|
serde |
Enable serde-based conversions |
sandbox |
Enable sandbox execution helpers |
shared-proto |
Enable shared prototypes for multi-VM scenarios |
Known Boundaries
- No C API and no direct loading of native C Lua modules
string.dumpproduces luars-specific bytecode- Some corners of
debug,io, andpackagestill differ from the official C Lua implementation
See ../../docs/Different.md for the detailed compatibility notes.
Documentation
| Document | Description |
|---|---|
| ../../docs/Guide.md | High-level embedding guide |
| ../../docs/UserGuide.md | High-level userdata guide |
| ../../docs/Async.md | High-level async and sandbox guide |
| ../../docs/Different.md | Known differences from C Lua |
License
MIT. See ../../LICENSE.