Closed chriskapp closed 5 years ago
Hello :-),
Creating a library à la wasm-bindgen is something we are thinking of.
We look at the Host Bindings API too, which can be adapted to PHP. This is not stable yet, though.
I would assume that we could also create a Uint8Array and pass this containing the string bytes to the wasm function?
Exactly, but you need to allocate some memory before, and it depends of your Wasm program. We can't just assume an alloc
or a dealloc
exported functions exist.
Would it help if I add examples to see how to handle strings, or more sophisticated data structures?
Hi, yes it would be really great if you could provide some examples howto pass and return more complex data structures to a function defined in wasm.
I am currently working on an API management tool where the endpoint logic can be developed by a user. It would be great if a user could upload a wasm file with a custom function which is then invoked by the API management tool for a specfic route. This would have the great advantage that the user could develop the endpoint logic in basically every programming language and is not bound to PHP. For this I would need to pass all request data to the wasm function as i.e. assoc array or object and then the wasm function could return a simple JSON encoded string.
@Hywan I believe that wasm-bindgen’s goal is for the underlying foundation to be able to support other languages - so one other option here might be trying to work with the wasm-bindgen folks to get a sense of how some of their underlying infrastructure can be re-used here.
@chinedufn True. We've already discussed about that with the wasm-bindgen folks. The project is closely tied to JS however. That's a big discussion to have: Between the language-interop itself, and the Host Bindings API.
Bonus: Recents commits (see #54 and #53) have boosted function invocation by 9.75 to 15.9%, and reduces memory usage by 1%.
@chriskapp I hope https://github.com/wasmerio/php-ext-wasm/blob/master/examples/greet.php is a good basis for you! Tell me if you need help :-).
@Hywan thank you very much, this looks really promising. I will try to implement this in my project and I will let you know whether everything works as expected.
Hi, I think the project looks really great. How would you pass a string to a function defined in wasm. The memory example shows how you could return a string from a function. I would assume that we could also create a
Uint8Array
and pass this containing the string bytes to the wasm function? In this case we could probably create in this lib some helper functions i.e. to convert a string toUint8Array
. Also Iam curious whether it would be possible to pass more complex data structures like assoc array (struct) to a wasm function?