Hi all,
So for my first adventure with emscripten I thought I'd start simple -- modify an existing bit of JS to call a c++ function to process an ArrayBuffer.
Oops.
Many hours later I think I understand the options with ccall/cwrap and embind. I have a working bit of code now which looks something like:
typedef int intPtr_t;
val processData(intPtr_t sourceBytes_, int byteLength)
{
const uint8_t *sourceBytes = reinterpret_cast<const uint8_t*>(sourceBytes_);
...
}
It's hacky, but it works, but .. it's hacky.
The "intPtr_t" typedef is there to get around embind's inability to handle raw pointers to primitives.
Is this seriously recommended practice? We have memory_view's to represent blocks of heap memory that can be returned to JS, but there seems to be no good solution going the other way from JS to c++. Am I totally missing something?
Maybe supporting std::array<> would make sense, like the existing support for std::string?
Our goal is to write a small library in c++ that can be compiled for both browsers/JS and native code. The above solution works, but it's embind-specific and implies wrapping certain APIs specifically for embind, which is of course error-prone and generally not fun.
Any suggestions would be most appreciated!