bytecodealliance / wasmtime-dotnet

.NET embedding of Wasmtime https://bytecodealliance.github.io/wasmtime-dotnet/
Apache License 2.0
409 stars 52 forks source link

`Caller.TryCallFunction` #233

Closed martindevans closed 1 year ago

martindevans commented 1 year ago

Added TryCallFunction methods to Caller. This allows functions to be called without allocating a Function object. An alternative solution would be to convert Function into a struct, but this is a much larger change!

The main shortcoming with this is that ValueBox cannot be stack allocated. So this API is really just passing the buck on allocating anything - the caller can avoid allocations (rent an array) but it's not very ergonomic. See the unit tests for example.

Another implementation could have generic arguments for all possible call/return combinations (and then use ValueBox.Converter<T>().Box(value)). This would be a fairly nice API to use, but would require generating yet more huge blobs of code.

I'm open to other suggestions on a better way to pass arguments and results.

martindevans commented 1 year ago

Superseded by #235