Skip to main content

lua_calls_rust/
lua_calls_rust.rs

1//! lua calls rust through the public embedding API.
2use moonseed::*;
3mod support;
4use support::*;
5fn main() -> ExampleResult {
6    let mut registry = HostRegistry::new();
7    registry.typed(
8        "example.scale",
9        NativePolicy::VmLocal,
10        |_cx, (x, scale): (i64, i64)| Ok(x.wrapping_mul(scale)),
11    );
12    let mut rt = Runtime::builder().registry(registry).build()?;
13    let scale = rt.make_closure("example.scale", ())?;
14    rt.globals().raw_set(&mut rt, "scale", scale)?;
15    assert_eq!(eval::<i64>(&mut rt, b"return scale(6, 7)")?, 42);
16    Ok(())
17}
18
19#[cfg(test)]
20#[test]
21fn example_runs_and_asserts_its_result() {
22    main().unwrap();
23}