-
Notifications
You must be signed in to change notification settings - Fork 824
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
Callbacks between Wasm and Native code #670
Labels
🎉 enhancement
New feature!
Comments
I believe this is the same as or very similar to #638 ; Thanks for the report -- I agree that this is an important thing to be able to do! |
This was referenced Sep 16, 2019
bors bot
added a commit
that referenced
this issue
Sep 19, 2019
803: Add method to call function at index on Ctx r=MarkMcCaskey a=MarkMcCaskey For #638 and #670 ```Rust fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 { println!("{}", guest_fn); let guest_fn_typed = unsafe { guest_fn }; let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap(); println!(" -> {:?}", result); 0 } ``` is what this looks like from the Host side # Review - [x] Create a short description of the the change in the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]> Co-authored-by: Mark McCaskey <[email protected]>
I got this working in #803 with an example!! |
bors bot
added a commit
that referenced
this issue
Sep 19, 2019
803: Add method to call function at index on Ctx r=MarkMcCaskey a=MarkMcCaskey For #638 and #670 ```Rust fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 { println!("{}", guest_fn); let guest_fn_typed = unsafe { std::mem::transmute(guest_fn) }; let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap(); println!(" -> {:?}", result); 0 } ``` is what this looks like from the Host side See `examples/callback.rs` for an example that doesn't require `transmute` # Review - [x] Create a short description of the the change in the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]> Co-authored-by: Mark McCaskey <[email protected]>
Closing because #803 merged in. If you have any issues, don't hesitate to reopen this issue or file a new one! |
This weekend I'll have time to integrate this change into my project. I'll let you know how it goes! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
I would like to use callbacks between Wasm and native code. I would like to implement a callback on the Wasm-side, pass it as an argument, and later invoke it from the native-side.
I basically want to do what's in this StackOverflow question, but with Wasmer and Rust.
Proposed solution
On the native-side, which is embedding the VM, I want to receive a pointer to a function implemented on the Wasm-side, and somehow lookup and dispatch that function. I would like to be able to do this without any shims or exported functions.
It might look something like this:
Additional context
I've attempted #245, but I haven't made any progress there. (Help please!)
I've implemented callbacks in my own demo project, but it required some pretty undesirable work-arounds, like a export function shim.
There was also some discussion on Spectrum.
The text was updated successfully, but these errors were encountered: