Have ideas to improve npm?Join in the discussion! »

    @fxtop/winffi

    0.1.1 • Public • Published

    winffi

    Node.js Foreign Function Interface For Windows

    Build Status PRs Welcome

    winffi is compiled product of node-ffi for windows and it's usage is the same with node-ffi. node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code.

    It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C. See the example/factorial for an example of this use case.

    NOTICE: the different between winffi and node-ffi is the winffi doesn't dependent on any build tools that node-ffi need.

    WARNING: node-ffi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.

    Example

    var winffi = require('@fxtop/winffi');
     
    var libm = winffi.Library('libm', {
      'ceil': [ 'double', [ 'double' ] ]
    });
    libm.ceil(1.5); // 2
     
    // You can also access just functions in the current process by passing a null
    var current = winffi.Library(null, {
      'atoi': [ 'int', [ 'string' ] ]
    });
    current.atoi('1234'); // 1234

    For a more detailed introduction, see the node-ffi tutorial page.

    Requirements

    • Only Support Windows.
    • The current version is tested to run on node v0.6, v0.8, v0.9 and v0.10.

    Installation

    $ npm install @fxtop/winffi

    Types

    The types that you specify in function declarations correspond to ref's types system. So see its docs for a reference if you are unfamiliar.

    V8 and 64-bit Types

    Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point (FP) numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.

    Call Overhead

    There is non-trivial overhead associated with FFI calls. Comparing a hard-coded binding version of strtoul() to an FFI version of strtoul() shows that the native hard-coded binding is orders of magnitude faster. So don't just use the C version of a function just because it's faster. There's a significant cost in FFI calls, so make them worth it.

    License

    MIT License. See the LICENSE file.

    Install

    npm i @fxtop/winffi

    DownloadsWeekly Downloads

    1

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    433 kB

    Total Files

    23

    Last publish

    Collaborators

    • avatar