Use node-ffi-napi via decorators.
It got tiresome maintaining separate type declarations and mappings for all our
node-ffi-napi code. This library has made things a little less painful so hopefully it can be useful to others.
It gives you:
- Typed calls to native libraries
- Automatic 'promisifcation' using the ffi
- Automatic handling of callback pointer lifetime
Only tested in TypeScript where you'll need these options enabling in your
ffi-napiis a peer dependency so you'll need to install a version which is compatible with your node version.
;// Create a class instance and native calls are proxied;myLib.do_some_number_fudging10, 546;// do_long_running_thing returns a promise so// this automatically uses the ffi async feature;// Callback pointers are cached to avoid GCmyLib.something_with_callback5,// This will actually call specific_namemyLib.whateverYouLike16;// Optionally supply the full path to your library;