I saw this already: https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime/topic/Pass.20string.20to.20and.20return.20string.20back.20from.20WASM.20function
But I don't really want to use wit
. Is that the only way, even though it's not stable yet?
Is there a manual way I can load a string into memory and have the guest function read it, without using unsafe?
You could always export custom memory management functions from the guest for the host to call to allocate space in the guest's linear memory. The host could then allocate the space, copy the string into it, and then pass the address to the guest; you'd be on your own to figure out ownership semantics for the allocation, though.
we do hope that eventually we get to the place where this is pretty much handled for you with minimal fuss with the component model and wit (or perhaps some more proc-macro magic in the future), however.
Thanks! Didn't realize that was the trick, and I couldn't find any examples in the wasmtime repo labelled "string".
I put up my example code if any other noobs happen across the thread https://six-five-six-four.com/git/reactor/wasm_test
Can't believe serde_json compiles down to 56 KB of wasm... on disk anyway.
ReactorScram has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC