You can't directly access C++ global variables via embind, but you can export a function which will return the variable (this is known as the "singleton pattern") and export that to JavaScript. You need to also bind the class, or else embind won't know how to expose the instance methods etc.
Something like this ought to work:
class MyClass {
...
public:
void doSomething();
}
static MyClass* singleton_val;
MyClass* singleton() {
if (singleton_val == NULL) {
singleton_val = new MyClass;
}
return singleton_val;
}
EMSCRIPTEN_BINDINGS(my_module) {
class_<MyClass>("MyClass")
... bindings for class ...;
function("singleton", &singleton, allow_raw_pointers());
}
(Or set the value from your main() and ensure it gets called before use.)
Then from the JS side you'd call it like:
Module.singleton().doSomething();
-- brion