Expand description
luna — a Lua runtime in pure Rust with a Cranelift-backed JIT.
Primary dialect: Lua 5.5 (tracks official upstream). Compat modes: Lua 5.1 / 5.2 / 5.3 / 5.4.
This crate is luna-core plus:
- the Cranelift-backed method + trace JIT (
jit_backend); - the
lua.h-compatible C ABI (capi); - the
lunaCLI bin.
Pure-Rust embedders that don’t want the JIT (and don’t want
Cranelift in their dependency tree) can depend on luna-core
directly — its API surface is a subset of this crate’s.
§Embedding contract
use luna_jit::{Vm, LuaVersion};
// JIT-equipped Vm, fully-loaded stdlib:
let mut vm = luna_jit::new_with_jit(LuaVersion::Lua55);
vm.eval("return 1 + 2").unwrap();Sandbox embedders should call vm.set_jit_enabled(false) and
vm.set_bytecode_loading(false) before running untrusted
scripts. See luna-core rustdoc for the full caveat list.
Re-exports§
pub use lua_facade::IntoLuaArgs;pub use lua_facade::Lua;pub use lua_facade::LuaFunction;pub use lua_facade::LuaRoot;pub use lua_facade::LuaSandboxBuilder;pub use lua_facade::LuaTable;
Modules§
- capi
- C ABI surface — a minimal viable
lua.h-equivalent that lets existing C/C++ hosts link against luna. Not a full PUC reimplementation; the subset here is the one needed to drive a Vm from a C caller: create/close state, load + pcall, push/to integer/string/boolean/nil, get/setglobal, stack height, type queries, plus C-side callbacks vialua_pushcfunction/lua_register. - compiler
- AST → bytecode compiler. Register model follows PUC lparser/lcode:
locals pin the low registers, temporaries grow from
freereg, constants are deduplicated, forward jumps are patch lists (plain Vecs instead of PUC’s in-code jump chains). Function nesting is a stack ofLevels; upvalue resolution walks it (PUC singlevaraux). - frontend
- Source → AST frontend (P01). Syntax only: scope resolution, constant folding and code generation live in later phases.
- inspect
- v2.0 Track TL — pure-read inspection accessors over a live
Vm. Re-exportsluna_core::vm::inspectso theluna-toolsbinaries (luna-heap-dump,luna-trace-inspect,luna-profile) canuse luna_jit::inspect::*without a separateluna-coredirect dep. - jit
- Unified
jitnamespace — combines luna-core’s trait surface + pure types with luna’s Cranelift-backed implementations. Existinguse luna_jit::jit::TraceRecord,use luna_jit::jit::CraneliftBackend,use luna_jit::jit::cache_lookup_or_compile, etc. resolve through this module. - jit_
backend - P11 — JIT pipeline (luna crate side; the trait surface and pure
data types live in
luna_core::jit). - lua_
facade - mlua-style
Luafacade (B12, Phase 2 P2-D). - numeric
- Lua numeral conversion core (stone candidate: pure functions, no runtime
types). Two consumers: the lexer (literal tokens, shape pre-validated by
scanning) and the VM/stdlib (
str2num— luaO_str2num semantics with whitespace and sign). Versioning is expressed as capability flags so this module stays dialect-agnostic. - pattern
- Lua pattern matching engine — a faithful port of lstrlib.c’s matcher. Pure functions over byte slices (stone candidate: no runtime types).
- runtime
- Runtime core: values, GC heap, strings, tables, function objects.
- version
- Lua dialect selection.
- vm
- Bytecode VM (P03): instruction set, errors, interpreter, builtins.
Structs§
- Vm
- A Lua virtual machine: one OS thread’s worth of Lua state.
Enums§
- LuaVersion
- Lua dialect the VM emulates. Drives lexer, parser, and runtime feature
gating.
Lua55is the primary; the others are compat modes;MacroLua(v1.3 Phase ML) is an additive dialect built on top of the 5.4 base.
Traits§
- VmExt
- Extension trait that exposes the JIT-installing constructors and
the
install_default_jitshim as methods onluna_core::vm::Vm. Bring it into scope withuse luna_jit::VmExt;to writevm.install_default_jit()(matches v1.0 syntax) instead ofluna_jit::install_default_jit(&mut vm).
Functions§
- install_
default_ jit - v1.1 A1 Session C — install the default Cranelift backend on an
already-constructed Vm. Idempotent on a JIT-equipped Vm; useful
for re-arming a Vm previously running under
install_null_jit. - new_
minimal_ with_ jit - v1.1 A1 Session C — build a JIT-equipped minimal Vm. Equivalent
to
luna_core::vm::Vm::new_minimal(version)followed byinstall_default_jit(&mut vm). Use this as the v1.0 drop-in replacement forVm::new_minimalcallers who want the Cranelift backend. - new_
with_ jit - v1.1 A1 Session C — build a JIT-equipped, fully-loaded Vm.
Equivalent to
new_minimal_with_jit(version)followed byvm.open_all_libs(). Use this as the v1.0 drop-in replacement forluna_jit::Vm::newcallers.
Attribute Macros§
- lua_
userdata_ methods - Walks the methods of an
impl T { ... }block and, for each one tagged with a helper attribute (#[lua_method("name")]etc.), emits the correspondingUserdataMethodsbuilder call inside a hidden__luna_userdata_registerassociated fn.
Derive Macros§
- LuaUserdata
- Emits the
luna_core::vm::LuaUserdatatrait impl for a struct.