I haven't used embind yet, but if you just want to pass a typed array as C 
array you don't actually need embind, just an 'exported' C function.

On the C/C++ side it's a normal C function (inside an extern "C" { } block 
so that the function name isn't mangled) taking pointer arguments, 

https://github.com/floooh/yakc/blob/6258e809c9f90cfa6e96bd57ad0a16eb0915e1d1/src/yakcapp/Main.cc#L480

...and on the JS side the usual Module.ccall with an 'array' typehint:

https://github.com/floooh/yakc/blob/6258e809c9f90cfa6e96bd57ad0a16eb0915e1d1/web/emsc.js#L141

For general interaction I'm planning to use this extern "C" { } with a 
small set of C interface functions instead of trying to move C++ data types 
back and forth (which IMHO just makes things more complicated).

Cheers,
-Floh.

Am Dienstag, 21. Februar 2017 06:28:13 UTC+1 schrieb Tyler Daniel:
>
> 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!
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to