Skip to main content

sim_lib_lang_lua/
runtime.rs

1use sim_kernel::{Cx, Ref, Result, Symbol, Value};
2use sim_lib_control::Coroutine;
3use sim_lib_mutation::{MutableTable, mutable_table, mutable_table_value};
4
5/// Builds a Lua coroutine that alternates between two ref lanes.
6///
7/// Lowers Lua coroutines onto the control organ's [`Coroutine`] rather than
8/// defining bespoke coroutine semantics.
9pub fn lua_coroutine(first: Vec<Ref>, second: Vec<Ref>) -> Coroutine {
10    Coroutine::alternating(first, second)
11}
12
13/// Constructs a Lua table from keyed entries as a mutation-organ table value.
14///
15/// Lowers Lua tables onto the mutation organ's [`MutableTable`]; mutating the
16/// result requires the standard mutate capability.
17pub fn lua_table(cx: &mut Cx, entries: Vec<(Symbol, Value)>) -> Result<Value> {
18    mutable_table(cx, entries)
19}
20
21/// Borrows the [`MutableTable`] backing a Lua table value.
22pub fn lua_table_value(value: &Value) -> Result<&MutableTable> {
23    mutable_table_value(value)
24}