-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example for string/vec u8 transfer #41
Comments
Did you figure it out? |
From Discord channel: ElegantBeef: Machine-Jonte: Wildbook — Today at 3:26 PM The Rust bindings last I looked at the did not have the pointer type (signature *) hooked up as a valid argument type, so you'll most likely want to either modify the library to allow for that by implementing the WasmArgs trait for *const T and *mut T or instead pass the pointer as u64 (which I wouldn't recommend but it'd make your life easier since you wouldn't need to modify the library). The main reason against implementing WasmArgs for *_ T is that it confuses the concept of WASM pointers with the concept of native pointers, so you might want to instead introduce a new WasmPtr type. Whichever you do you want to give it the signature token *. Past that you'll want to write a utility function that calls Runtime::memory / Runtime::memory_mut with the pointer / WasmPtr as argument and returns a native pointer to the memory it references. How you decide to perform bounds checks and uphold ownership and aliasing rules past that is up to you.. The WasmArgs trait is defined here: https://github.com/wasm3/wasm3-rs/blob/master/src/ty.rs If I remember correctly it should be reasonably easy to implement it for a new pointer-esque type, but I don't remember the details around how you'd do so and still keep your stack and slots valid. I don't think it'll be hard to, but I'm not going to pretend I know that it's simple. You can find example function with pointer arguments if you look at the wasm3 built-in uvwasi implementation:
Hence you expose a function that allocates from within to ensure that the allocator on the inside is fully aware of what's going on and fully responsible for managing all the in-WASM memory. Same goes for freeing that memory. Machine-Jonte — Today at 3:39 PM Wildbook — Today at 3:41 PM Machine-Jonte — Today at 3:42 PM Wildbook — Today at 3:46 PM Machine-Jonte — Today at 3:58 PM Wildbook — Today at 4:02 PM |
WebAssembly does not have |
Is there an example that can show passing a String or a Vec both ways?
The text was updated successfully, but these errors were encountered: