Hi,
I can't seem to find example code of how to pass an ArrayBuffer from JS to C via ccall() (for instance, there doesn't seem to be a test for this in the SDK?), and I have problems doing this (the passed data is broken). I'm sure it's something simple...
Background: I want to pass file content data from a JS drag-n-drop event handler to the C side.
What I have on the JS side:
...
// this is the array buffer as result of a FileReader, this contains the
// expected data (I checked through logging the first couple of bytes to the console)
var content = loadEvent.target.result;
// now the ccall to a C function "emsc_pass_data" with 3 params, a string name, the content, and the length
Module.ccall('emsc_pass_data',
null,
['string', 'array', 'number'],
...
...and on the C side I have:
void emsc_pass_data(const char* name, const uint8_t* data, int size) {
}
The function is called, name has a valid string, size is also right, data is some pointer, but the pointed-to data behind the pointers doesn't match the ArrayBuffer content (it looks fairly random with lots of zeros).
What am I doing wrong? I would most appreciate some code example to look at :)
Cheers,
-Floh.