Accessing an SDK that is written in c++ using node.js

。_饼干妹妹 提交于 2019-12-05 13:31:01

You can use the native V8 API for that. You will need to provide a layer over your C++ code and expose it as Javascript entities.

if there's also a C-style interface you could use node-ffi https://github.com/node-ffi/node-ffi

If you're using electron 3 (which in turn uses Node 10), you can use N-API which has great examples on how to wrap a C++ object into a JS object. N-API is stable and supported by Node 10, so it's a pretty good choice over NaN and node-addon-api for the long term.

https://nodejs.org/api/n-api.html

Here's a repository of examples that proves pretty useful. This one specifically is for wrapping C++ objects. https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/6_object_wrap/napi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!