Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <emscripten/bind.h>
- #include <iostream>
- using namespace emscripten;
- void changeGlobalVar()
- {
- // Get 'globalVar' variable from JS
- // The 'val' datatype allows you to get JS objects, set their attributes,
- // call their methods and much more as specified here
- // https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#using-val-to-transliterate-javascript-to-c
- val globalJSVar = val::global("globalVar");
- // Set globalVar.name to "Scott Burgert"
- globalJSVar.set("name", val("Scott Burgert"));
- // Set globalVar.ID to 12345
- globalJSVar.set("ID", val(12345));
- // Call 'globalVar.display()'
- // display() does not need any arguments, however if it did, you would just pass
- // arguments into the parameters after the method name parameter
- //Arg: returnType | funcName | args
- globalJSVar.call<void>("display");
- }
- EMSCRIPTEN_BINDINGS(Module)
- {
- function("changeGlobalVar", &changeGlobalVar);
- }
Advertisement
Add Comment
Please, Sign In to add comment