SHARE
TWEET

Untitled

quantumech Apr 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <emscripten/bind.h>
  2. #include <vector>
  3.  
  4. using namespace emscripten;
  5.  
  6. // Method that gets called by JS to return a vector
  7. std::vector<int> returnVector()
  8. {
  9.     // Initialize vector with values {4, 5, 6}
  10.     std::vector<int> vec;
  11.     vec.push_back(4);
  12.     vec.push_back(5);
  13.     vec.push_back(6);
  14.  
  15.     return vec;
  16. }
  17.  
  18. // Register vector and factory method
  19. EMSCRIPTEN_BINDINGS(Module)
  20. {
  21.     register_vector<int>("vector<int>"); // <-- Register vector<int> as a JS datatype
  22.                                              // You are able to do the same thing with maps..
  23.     function("returnVector", &returnVector); // as well. Just swap out 'register_vector' for 'register_map'
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top