#node c++扩展模块
简介:
- node支持编写c/c++扩展模块以提高响应速度
- 扩展模块属于文件模块
- 适用于部分复杂且耗cpu的计算(可放置子线程中进行)
创建:
// 创建test.cpp
#include <node.h>
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void CAMOpen(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "cam_open..."));
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "CAMOpen", CAMOpen);
}
NODE_MODULE(FaceRecognition, init);
// 创建binding.gyp
{
"targets": [
{
"target_name": "test",
"sources": [ "test.cpp" ]
}
]
}
// 安装编译环境
npm install -g node-gyp
// 在test.cpp目录下编译
node-gyp configure build
// 测试
const test &#