Function with args
Is there any plan/ETA to support function calls with args/return values ?
Do you mean in the context of exported functions? For those, there is no current plan. We're open to contributions! Though we'd prefer a discussion of an implementation plan before receiving a PR to save time if there is a fundamental issue with the approach.
I think this can be extremely useful! Having able to export functions that can accept inputs and return an output + import functions to webassembly means we can create wasm files that potentially can be run anywhere even non-javascript environments!
I'm experimenting with a variation of this in QuickJs4J (which is based on Javy):
https://github.com/roastedroot/quickjs4j/pull/33
Prerequisites:
- we are generating dynamic bindings host/guest so that the guest(JS) can easily invoke anything on the host(Java for us)
- we are already enabling function returns: is a special case of host invocation with a single value that is the result
Design:
- we compile the user JS library and we control the input stream
- we generate the dynamic JS code that will invoke the function and return the result to the host
- the input stream contains JSON defining:
- the function to be invoked
- the arguments to be passed
Goals: Have JS code written in a library that can be compiled once and re-used for dynamic function invocation of multiple "entrypoints".
I doubt I'd have the time to try to port this approach in this codebase, but sharing as it might be a starting point for someone else(the design is completely ).
@jeffcharles 🙏 thanks again for the chat we had at WASM/IO, you can see that I'm making effective use of your suggestions 🙂 and enjoying the journey!