bytecodealliance / wasmtime-dotnet

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

Added support for Linker.DefineFunction with generic tuples #285

Closed martindevans closed 10 months ago

martindevans commented 10 months ago

Added support for defining functions which have a tuple as a generic parameter.

Previously defining like this would work:

Linker.DefineFunction<int, int, int>("module", "name", (int a) => (a, a));

But doing this would not work:

void DefineWrapper<TIn, TOut>(Func<TIn, TOut> func)
{
    Linker.DefineFunction<TIn, TOut>("module", "name", func);
}

DefineWrapper<int, (int, int)>((int a) => (a, a));

Even though they're ultimately doing the same thing, just with one more level of generic typing.

This PR detects that case and adds limited support for tuples (only up to 4 elements).

I have not added support for ValueRaw unboxing of tuples. As far as I can tell it's not required anywhere.