SkillAgentSearch skills...

Jsb

Bind C++ to JavaScript, inspired by Embind from the Emscripten SDK.

Install / Use

/learn @sakrist/Jsb
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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

Non-essential - out of scope:

More for reference: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html

Configuration

Related Skills

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated20d ago
Forks0

Languages

C++

Security Score

90/100

Audited on Mar 13, 2026

No findings