-
Howdy. I'm attempting to embed wasmi and then call an AssemblyScript-written function. All is well, until I try and pass a more complex structure. Without further ado: #[wasm_bindgen]
#[allow(dead_code)]
struct SomeStruct {
afield: i32,
}
let add =
instance.get_typed_func::<(<SomeStruct as IntoWasmAbi>::Abi, i32), i32>(&store, "add")?;
let some_struct = SomeStruct { afield: 10 };
let result = add.call(&mut store, (some_struct.into_abi(), 10))?;
println!("result: {}", result); On executing
So, I'm clearly doing something wrong, or I've made an assumption that wasm bindgen is passing JS types in exactly the same way as JS in the browser would when calling out to the same file (which works). Here's the AssemblyScript being called: class SomeStruct {
afield!: i32;
}
export function add(a: SomeStruct, b: i32): i32 {
return a.afield + b;
} ...and here's the JS when calling from the browser: add({ "afield": 10 }, 2) Any pointers on how JS types like this can be passed around? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I am clearly not an expert in this area of use cases or in AssemblyScript but given that you want to use Wasm interprocessing with complex custom types you probably want to take a look into this fork of WIT is the format for the interface types Wasm proposal which was made exactly for the purpose of exchanging interface information between different languages, e.g. JS and AssemblyScript via Wasm. |
Beta Was this translation helpful? Give feedback.
Well, I spent quite a bit of this week learning how to pass complex types around between a WASMI host written in Rust, and a Rust based WASM program using the component model.
I won.
The approach I took: