Jsb
Bind C++ to JavaScript, inspired by Embind from the Emscripten SDK.
Install / Use
/learn @sakrist/JsbREADME
Project Description
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.
NOTE
It is impossible to make multiple synchronous calls from JavaScript to C++ due to limitations imposed by the browser.
Samples
- [x] macOS - look in macOS directory
- [ ] iOS
- [ ] Android
- [ ] Windows
macOS
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();
Features list
Essential:
- [x] bind a class
- [x] bind regular functions of a class
- [x] bind const functions of a class
- [x] bind static functions of a class
- [x] bind simple constructor of a class
- [x] bind global functions
- [x] generate funcitons JavaScript code based on bindings
- [x] delete function for a C++ class
- [x] 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
- [x] bind vectors
Non-essential
-
[ ] value types
-
[ ] smart pointers
-
[ ] Type conversion
-
[ ] 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
Configuration
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
