Advertisement
quantumech

Untitled

Apr 23rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <emscripten/bind.h>
  2. #include <iostream>
  3.  
  4. using namespace emscripten;
  5.  
  6. // Define constant being exposed
  7. const double PI = 3.141592653589793238463;
  8.  
  9. // Expose PI constant to JS
  10. EMSCRIPTEN_BINDINGS(Module)
  11. {
  12.     constant("PI", PI);
  13. }
  14.  
  15. Return pointer to a variable
  16. -----------------------------
  17. #include <emscripten/bind.h>
  18. #include <iostream>
  19.  
  20. using namespace emscripten;
  21.  
  22. // Data being sent to JS via TypedArray
  23. // Has length of 309
  24. 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 ";
  25.  
  26. // Method being registered to JS
  27. // Returns handle to 'data'
  28. //
  29. // 'val' is defined by Emscripten and is used to return JS objects from C++
  30. val getAlotOfData()
  31. {
  32.     // In this particular instance,
  33.     // this method will return an Int8Array with with a handle to the 'data' variable's memory
  34.     // This means that you are able to edit the variable in JS because its essentially passing a
  35.     // pointer
  36.     //
  37.     // But Emscripten will return the JS TypedArray datatype makes the most sense
  38.     return val(typed_memory_view(309, data));
  39. }
  40.  
  41. // Register 'getAlotOfData()'
  42. EMSCRIPTEN_BINDINGS(Module)
  43. {
  44.     function("getAlotOfData", &getAlotOfData);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement