Stream: wasmtime

Topic: Canonical way to get value return by host function


view this post on Zulip Stephen (Nov 27 2024 at 19:41):

Hi, I'm trying to use rust wasmtime engine to instantiate wasm module and call its function, the function in the module could call some host functions to read some data on host machine, is there any canonical way to return the value to the wasm function? The current possible way I'm doing is by using get_export("memory") to get Memory for the wasm instance and write back the data to the Memory which wasm instance function can read, but want to see if there is any better way for this purpose? Thanks in advance!

view this post on Zulip Chris Fallin (Nov 27 2024 at 19:54):

What you want is the component model, and the wit-bindgen tool. It lets you define interfaces at a higher level, including with types like strings and lists, and generates bindings within the Wasm module and on the host side that let you call functions easily. You'll find examples in our documentation here. Let us know if you have any questions!

view this post on Zulip Stephen (Nov 27 2024 at 20:31):

Cool, will read this, thanks!


Last updated: Dec 23 2024 at 14:03 UTC