Gameplans: Modularity of Mods

[This is a post from February that, apparently, was never posted. Info may be outdated by now.]

That leads me to this implementation, which you can embed from a Rust application:

https://docs.wasmtime.dev/lang-rust.html

To be honest much of the concepts in that project are over my head. Lin Clark’s blog posts make sense to me though :slight_smile:

As far as I can tell we would use wasmtime as a run-time library to load mods (WASM based) into Mechaenetia (Rust based). With wasmtime we can call WASM functions from Rust code, with code that looks reminiscent of Java reflection. This is what the call looks like:

// store holds compiled WASM for a function "test_func()" which takes no
// arguments and returns an i64. instance is an instance of the store.
let test_func = instance.get_func(&mut store, "test_func")
    .unwrap()
    .typed::<(), i64, _>(&store)?;
println!("testfunc() = {:?}", test_func.call(&mut store)?);
// store also holds compiled WASM for a function "test_func2()" which takes two
// u32s as arguments and returns an u64
let test_func2 = instance.get_func(&mut store, "test_func2")
    .unwrap()
    .typed::<(u32, u32), u64, _>(&store)?;
println!("test_func2(2, 8) = {:?}", test_func2.call(&mut store, (2, 8))?);

These are the calls the Mechaenetia team would use to interact with the mod API through WASM, if test_func() -> i64 and test_func2(u32, u32) -> u64 were in the API. Right?

~Max

2 Likes