quantumech

Untitled

Apr 23rd, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <emscripten/bind.h>
  2. #include <iostream>
  3.  
  4. using namespace emscripten;
  5.  
  6. void changeGlobalVar()
  7. {
  8.     // Get 'globalVar' variable from JS
  9.     // The 'val' datatype allows you to get JS objects, set their attributes,
  10.     // call their methods and much more as specified here
  11.     // https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#using-val-to-transliterate-javascript-to-c
  12.     val globalJSVar = val::global("globalVar");
  13.  
  14.     // Set globalVar.name to "Scott Burgert"
  15.     globalJSVar.set("name", val("Scott Burgert"));
  16.  
  17.     // Set globalVar.ID to 12345
  18.     globalJSVar.set("ID", val(12345));
  19.  
  20.     // Call 'globalVar.display()'
  21.     // display() does not need any arguments, however if it did, you would just pass
  22.     // arguments into the parameters after the method name parameter
  23.         //Arg:  returnType | funcName | args
  24.     globalJSVar.call<void>("display");
  25. }
  26.  
  27. EMSCRIPTEN_BINDINGS(Module)
  28. {
  29.     function("changeGlobalVar", &changeGlobalVar);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment