wasm-examples
wasm-examples copied to clipboard
Can I use the same example with Data structure?
Can i use the same example with the structure and pass the variable structure to javascript with one function example:
C Code:
`struct number { int x; int y; } num;
int numberfun () { num.x=100; num.x=400; return num; } `
Maybe not.
A more practical way is to encode your c++ data structure into binary and decode it in the javascript.
Thank for your response.
You know my first problem was how to pass multiple variables in the same function but after some research i saw that is impossible and i wanted to try data structures.
I want to ask you if the encode and decode data structures is the best solution for my first problem or exist another solutions
In my opinion, encode and decode the data in WebAssembly.Memory
is the most efficient way (for now).
However, the Emscripten also provides the Embind
and WebIDL Binder
technology to bind C++ data structures to js, but it relies on extra IDL or js "glue" file to achieve that. It's convenient but seems expensive. Under the hood, I think it still based on encoding and decoding the WebAssembly.Memory
(not confirmed).
Thank you for your quick and helpful response and also for the links.