kawamuray / wasmtime-java

Java or JVM-language binding for Wasmtime
Apache License 2.0
128 stars 29 forks source link

Returning a multi-value from a wrapped function #24

Closed zacharywhitley closed 3 years ago

zacharywhitley commented 3 years ago

Is there any way to return a multi-value from a wrapped function?

kawamuray commented 3 years ago

No. The purpose of wrapper interfaces defined in WasmFunctions is to provide a Java-native APIs to interact with wasm functions. Java has no support for multi return value, so there's no straight mapping possible.

You can just use Func class directly to obtain array of results, and/or give it handler that stores multiple result values.

              Func func = new Func(store, fnType,
                     (caller, params, results) -> {
                         results[0] = ...;
                         results[1] = ...;
                         return Optional.empty();
                     });
zacharywhitley commented 3 years ago

Thanks. Just what I was looking for.