quantumech Apr 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <emscripten/bind.h>
- // Bring Emscripten namespace into scope for the sake of readability
- using namespace emscripten;
- // Struct that is treated in JS like an array. 'returnX(Point(1,5))' => 'Module.returnX([1,5])'
- // This struct is treated like an array because it is being registered as a 'value_array'
- struct Point
- int x;
- int y;
- int returnX(Point pt)
- return pt.x;
- value_array<Point>("Point") // <-- Register 'value_array' called 'Point'. 'value_arrays'
- // are structs that are treated like arrays in JS.
- .element(&Point::x) // <-- Set 'Point::X' to be the first element
- .element(&Point::y); // <-- Set 'Point::Y' to be the second element
- function("returnX", &returnX); // <-- Register method to return the X value of 'Point' struct
RAW Paste Data