Skip to main content

Crate luna_jit

Crate luna_jit 

Source
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 luna CLI 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 via lua_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 of Levels; 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-exports luna_core::vm::inspect so the luna-tools binaries (luna-heap-dump, luna-trace-inspect, luna-profile) can use luna_jit::inspect::* without a separate luna-core direct dep.
jit
Unified jit namespace — combines luna-core’s trait surface + pure types with luna’s Cranelift-backed implementations. Existing use 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 Lua facade (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. Lua55 is 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_jit shim as methods on luna_core::vm::Vm. Bring it into scope with use luna_jit::VmExt; to write vm.install_default_jit() (matches v1.0 syntax) instead of luna_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 by install_default_jit(&mut vm). Use this as the v1.0 drop-in replacement for Vm::new_minimal callers 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 by vm.open_all_libs(). Use this as the v1.0 drop-in replacement for luna_jit::Vm::new callers.

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 corresponding UserdataMethods builder call inside a hidden __luna_userdata_register associated fn.

Derive Macros§

LuaUserdata
Emits the luna_core::vm::LuaUserdata trait impl for a struct.