Skip to content
This repository was archived by the owner on Feb 21, 2018. It is now read-only.
This repository was archived by the owner on Feb 21, 2018. It is now read-only.

Platform-agnostic API example #32

@jjrv

Description

@jjrv

nbind is a C++ template based bindings generator with an API designed around C++ standard library types. That way it avoids JavaScript engine details and already the same code can be compiled to native Node.js addons and asm.js code that can be imported using Node.js require or inside a browser with most loaders.

The next planned step is to serialize function arguments in a common binary format and compile the addon to a .so, .dll or .dylib so it can provide a stable ABI within a single platform (all versions of Node.js and Electron). Emscripten's embind uses a similar serialization approach that works in practice.

nbind also generates TypeScript definitions from the C++ code and has tools for managing binding.gyp files. An addon looks for example like:

class VectorTest {
public:

  static std::vector<int> getInts() {
    std::vector<int> a {{ 13, 21, 34 }};
    return(a);
  }
};

NBIND_CLASS(VectorTest) {
    method(getInts);
}

For example there's a RisingStack tutorial for Node.js addons using NAN, and you can compare its example to an nbind-based version.

I'm really interested to see what others are coming up with. nbind is one possible way to provide a stable ABI (in the future) across all Node.js versions, and a stable API (already today) across all JavaScript implementations on all platforms in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions