The idea of the project is to create the ability to control C++ objects from JavaScript code, similar to what Emscripten provides to developers but with a limited feature set due to memory access limitations. The project is inspired by Emscripten's embind and later by Boost.Python.
It is impossible to make multiple synchronous calls from JavaScript to C++ due to limitations imposed by the browser.
- macOS - look in macOS directory
- iOS
- Android
- Windows
Look into ViewController.mm
to see on how to register Bridge communicator.
Example on how to bind C++ code:
class TestJSBinding {
public:
TestJSBinding() { }
int getNumber() {
return i;
}
void setNumber(int newi) {
i = newi;
}
int i;
}
jsb::class_<TestJSBinding>("TestJSBinding")
.constructor<>()
.function("setNumber", &TestJSBinding::setNumber)
.function("getNumber", &TestJSBinding::getNumber);
In javascript:
var object = new TestJSBinding();
object.setNumber(10);
var value2 = object.getNumber();
object.delete();
Essential:
- bind a class
- bind regular functions of a class
- bind const functions of a class
- bind static functions of a class
- bind simple constructor of a class
- bind global functions
- generate funcitons JavaScript code based on bindings
- delete function for a C++ class
- execute generated JavaScript code at registerCommunicator
- val as wrapper around JS object - in progress - not possible
- EM_JS - read JS function's arguments and pass to a C++ function
- bind perfect forwarding functions of a class ??
- bind constructor with arguments of a class
- bind property members of a class
- implement typescript interafaces generator.
- bind enums
- bind vectors
Non-essential
-
smart pointers
-
EM_ASYNC_JS
-
simple EM_ASM
Non-essential - out of scope:
-
Deriving from C++ classes in JavaScript
-
advanced EM_ASM from em_asm.h
More for reference: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html