js-ctypes is a foreign-function library for Mozilla’s privileged JavaScript. It provides C-compatible data types and allows JS code to call functions in shared libraries (dll, so, dylib) and implement callback functions. The interface and implementation are modeled on the
Python ctypes module.
The main objective for the library is to help developers avoid building binary (C++)
XPCOM components when only a simple wrapper is needed. Such situations include:
- Developer wants functionality not built into the Mozilla platform, but easily supported by the native OS.
- Developer wants to use a 3rd party library in an extension or XUL app.
- Developer has methods in native code for performance reasons.
The usual answer to these problems is creating a binary (C++) component to act as a wrapper so the native features can be exposed to JavaScript via XPCOM. However, the process of building binary XPCOM components is significantly harder than
JavaScript components. The macros and memory management rules of binary components are harder than JavaScript, but its really the compiler and linker flags, IDL, makefiles and SDK versioning that make the process painful. The build process must be repeated for each platform too. For many cases, its just too much work.
The goal of js-ctypes is to allow developers to declare methods in binary libraries and then expose those methods as callable JavaScript functions. Developers can then create pure JavaScript library wrappers around binary libraries - without making binary XPCOM wrappers.
https://wiki.mozilla.org/JSctypes
No comments:
Post a Comment