hi,
I would like to pass some data other than numbers to a WebAssembly function compiled by TeaVM through a serialization in the memory buffer.
So if my Javascript code looks like this:
const memory = new WebAssembly.Memory({initial: 256});
const array = new Int16Array(memory.buffer);
array.set(firstElement, 0);
...
WebAssembly.instantiate(..., {env: {memory: memory}, teavm: {...}}).then(... instance.exports.myWebAssemblyFunction());
How can I read this data located at the beginning of the memory from the Java code that will be compiled by TeaVM?
I tried:
@Export(name = "myWebAssemblyFunction")
public static void myWebAssemblyFunction() {
Address address = Address.fromInt(0);
short firstElement = address.getShort(); // 16 bits type
...
}
Thinking that Address.fromInt(0) will point to the beginning of the memory but when I run this, I'm getting firstElement = 0 instead of my first element set by my JavaScript code, so that's probably not the right way.
What's the correct way to do this with TeaVM API?