Advertisement
quantumech

Untitled

Apr 23rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement