美文网首页
xcode开发node addon c++

xcode开发node addon c++

作者: zhangdz | 来源:发表于2019-08-16 17:52 被阅读0次

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

点击eidit scheme

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

选择nodejs

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

7、执行

8、断点调试

9、js调试

    1、修改arguemts

2、chrome 内调试js

相关文章

网友评论

      本文标题:xcode开发node addon c++

      本文链接:https://www.haomeiwen.com/subject/rgmqsctx.html