I am in the process of porting a crypto implementation to JS using 
emscripten.  The compilation of C++ code to js is pretty smooth. But I have 
some issues in dealing the interaction of JS and compiled C++ code. I have 
a few question and hope to get some advice from this list. 

1. In recent releases uses fastcomp, and and it seems embind no longer 
works. If I use 'extern "C"' to disable the c++ mangling, and use cwrap to 
call c function from Js, it should work, right?

2. I personally prefer to use "embind", that allow me to expose C++ class 
to JS directly. I will have to use 12.0 or earlier release. Is it a 
recommended practice? Can I expect embind be supported again?

3. I need to pass ArrayBuffer from JS to compiled C++ code, and get back a 
new (or modified) ArrayBuffer. It is not clear to me how can I do it. The 
simplified code will be something like this:
class MyCrypto {
   MyCryto();
 
   void Process(const string& input, vector<string>& output); 
};

EMSCRIPTEN_BINDINGS(MyCryptoModule) {
  class_<MyCrypto>("MyCrypto").constructor()
  .function("Process", &MyCrypto::Process);
  register_vector<std::string>("VectorString");
}


This code compiled well. But I don't know how JS code can be written to 
call function. 

var crypto = new Module.MyCrypto();
crypto.Process(...);

I would like the input to be ArrayBuffer, 
var input = new ArrayBuffer(256);

What will be the output look like? Will this work at all? 

If std::vector brings trouble, I can give it up and change "output" to be 
std::string. 
   void Process(const string& input, string& output); 

Compiler will complain about this form. 
error: non-const lvalue reference to type 'basic_string[[3 * ...]>' cannot 
bind to a temporary of type 'basic_string[[3 * ...]>

Thanks in advance

lucoy

 

-- 
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