how to pass js array to wasm ?
who can give me a exmaple ! thanks so much!
I believe you must pass it as a string.
So on the javascript side, you would do something like
myWasmFunction(JSON.stringify(myArray))
And on the tinygo side, you would have to unmarshal it with something like tinyjson (because encoding/json doesn't work in tinygo)
I believe you must pass it as a string. So on the javascript side, you would do something like
myWasmFunction(JSON.stringify(myArray))
Can you provide a full example about how to pass a string to wasm module? I thought this should be accomplished by
- manually allocating memory for the string inside wasm
- copying the string to the allocated memory
- passing to
myWasmFunctionaddress of the string start and string length. If we can do all the same with TinyGo in a different, simpler way, please, tell us how to do it.
Good news. Thanks to @trivigy, there's an example for this.
Follow the directions here, except make slices instead of make main https://github.com/tinygo-org/tinygo/blob/release/src/examples/wasm/README.md
I verified this just now. https://github.com/tinygo-org/tinygo/blob/release/src/examples/wasm/slices/wasm.go