Skip to content
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

Passing CLR objects to Wasmtime #80

Open
sr229 opened this issue Dec 4, 2021 · 2 comments
Open

Passing CLR objects to Wasmtime #80

sr229 opened this issue Dec 4, 2021 · 2 comments

Comments

@sr229
Copy link

sr229 commented Dec 4, 2021

Currently this runtime can execute Wasmtime one way, but there's no clear documentation how to pass CLR objects or return value types back to Wasmtime since execution engines like Wasmtime should expect return types from the host too.

@peterhuene
Copy link
Member

CLR objects can be passed to and from wasm as an externref type, which allows wasm to store a reference to the CLR object and pass it back to the host when needed, but externrefs cannot be used directly from wasm as they are, by definition, external to wasm itself. Thus they are considered to be immutable and unforgeable references of host objects since wasm has no instructions for interacting with externrefs directly.

This example shows how a host function could pass back a CLR String from a host function; the wasm function then returns the externref back to the host, allowing the host to then print the same string that was originally returned.

Perhaps it's not the clearest example of what is possible with support for the externref type. The .NET API will allow any .NET reference type in the host function's signature to bind to an import that takes an externref at that parameter's index.

@sr229
Copy link
Author

sr229 commented Dec 8, 2021

Thank you so much! I believe it's not a matter of not being clear, it's just that the official documentation is lacking or not sufficient/friendly enough to outside consumers because there's so much that wasn't explained. I hope that helps.

It would also be nice if the examples can be expanded to cover more advanced use cases like passing objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants