SHARE
TWEET

Untitled

quantumech Apr 23rd, 2019 (edited) 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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