SHARE
TWEET

Untitled

quantumech Apr 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <emscripten/bind.h>
  2.  
  3. // Bring Emscripten namespace into scope for the sake of readability
  4. using namespace emscripten;
  5.  
  6. // Struct that is treated in JS like an array. 'returnX(Point(1,5))' => 'Module.returnX([1,5])'
  7. // This struct is treated like an array because it is being registered as a 'value_array'
  8. struct Point
  9. {
  10.     int x;
  11.     int y;
  12. };
  13.  
  14. int returnX(Point pt)
  15. {
  16.     return pt.x;
  17. }
  18.  
  19. EMSCRIPTEN_BINDINGS(Module)
  20. {
  21.     value_array<Point>("Point") // <-- Register 'value_array' called 'Point'. 'value_arrays'
  22.                                 //     are structs that are treated like arrays in JS.
  23.         .element(&Point::x)     // <-- Set 'Point::X' to be the first element
  24.         .element(&Point::y);    // <-- Set 'Point::Y' to be the second element
  25.  
  26.     function("returnX", &returnX); // <-- Register method to return the X value of 'Point' struct
  27. }
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