Skip to main content

Module table_builder

Module table_builder 

Source
Expand description

TableBuilder + vm.table_of (B3, Phase 2 P2-B) — replace the dogfood §4.1 unsafe { t.as_mut() }.set(...) dance with a safe one-line builder.

use luna_core::vm::Vm;
use luna_core::version::LuaVersion;
use luna_core::runtime::Value;

let mut vm = Vm::sandbox(LuaVersion::Lua55).open_base().build();

// One-shot: table_of
let t = vm.table_of([("answer", 42_i64), ("year", 2026)]);
vm.set_global("constants", Value::Table(t)).unwrap();

// Multi-step: new_table builder
let t = vm.new_table()
    .with("name", "luna")
    .with("major", 1_i64)
    .with("minor", 1_i64)
    .build();
vm.set_global("info", Value::Table(t)).unwrap();

let r = vm.eval("return constants.answer + info.minor").unwrap();
assert_eq!(r.len(), 1);

The unsafe Gc::as_mut lives inside the builder; embedders never write it.

Structs§

TableBuilder
Multi-step table construction. Borrows &mut Vm for the whole builder window so no other Vm operation can interleave (which might trigger GC mid-build). Consume with TableBuilder::build.