Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <emscripten/bind.h>
- #include <iostream>
- using namespace emscripten;
- // Define constant being exposed
- const double PI = 3.141592653589793238463;
- // Expose PI constant to JS
- EMSCRIPTEN_BINDINGS(Module)
- {
- constant("PI", PI);
- }
- Return pointer to a variable
- -----------------------------
- #include <emscripten/bind.h>
- #include <iostream>
- using namespace emscripten;
- // Data being sent to JS via TypedArray
- // Has length of 309
- char* data = "sadiofhsdoithqrp;lstgnpoulgdfjna;gunhdfso;gljkpuahsptr hnweqopmftopirsmgrstm,rwheiopt,w qgtiop rno enbrgorlgnvolfsd;cgbunpqerbgnjla;sdfbgoufld;grqeibtgr pvmoqmwprul;tlmv qweuumpvthwuioetqvlqmw;etvumqhtvuiormthvqeuoitv,uhreamoithgl;hlajghknfihgrel;agheirgdoga;lhe;rhgoueobmopiamvrotmq3498vtm4p35ty;vmqa;tvyn ";
- // Method being registered to JS
- // Returns handle to 'data'
- //
- // 'val' is defined by Emscripten and is used to return JS objects from C++
- val getAlotOfData()
- {
- // In this particular instance,
- // this method will return an Int8Array with with a handle to the 'data' variable's memory
- // This means that you are able to edit the variable in JS because its essentially passing a
- // pointer
- //
- // But Emscripten will return the JS TypedArray datatype makes the most sense
- return val(typed_memory_view(309, data));
- }
- // Register 'getAlotOfData()'
- EMSCRIPTEN_BINDINGS(Module)
- {
- function("getAlotOfData", &getAlotOfData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement