1、安装node-gyp
npm install node-gyp -g
2、创建binding.gyp
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ],
"include_dirs": [
"<!(node -e \"require('nan')\")"
]
}
]
}
3、创建hello.cc
#include <nan.h>
void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::Function> cb = info[0].As<v8::Function>();
const unsigned argc =1;
v8::Local argv[argc] = {Nan::New("hello world").ToLocalChecked() };
Nan::Call(cb, info.Holder(), argc, argv);
}
voidInit(v8::Local exports) {
exports->Set(Nan::New("hello").ToLocalChecked(),
Nan::New(Method)->GetFunction());
}
NODE_MODULE(hello, Init)
4、创建hello.js
const addon = require('bindings')('hello');
addon.hello(function (res) {
console.log(res);
})
5、创建 xcode 工程
1、npm init
2、npm install bindings nan -s
3、node-gyp configure
4、node-gyp build
5、node-gyp configure -- -f Xcode
6、配置xcode scheme
1、选择scheme

2、编辑info, 点击executable 选择other,弹出对话框选择node


3、编辑arguments, 点➕ 输入刚创建的hello.js 目录

7、执行

8、断点调试

9、js调试
1、修改arguemts

2、chrome 内调试js
网友评论