Skip to content
/ jsb Public

Bind C++ to JS, inspired by embind emscripten SDK

License

Notifications You must be signed in to change notification settings

sakrist/jsb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • 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:

  • 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

Non-essential - out of scope:

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

Configuration

About

Bind C++ to JS, inspired by embind emscripten SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages