Skip to content

Instantly share code, notes, and snippets.

@hiroosak
Created July 26, 2014 16:13
Show Gist options
  • Save hiroosak/5c65c179c2c14474e19c to your computer and use it in GitHub Desktop.
Save hiroosak/5c65c179c2c14474e19c to your computer and use it in GitHub Desktop.
node-gypを使ってnative addonを作成する (1) - Hello World ref: http://qiita.com/taizo/items/dee4ee85fe6f4e28428b
{
"targets": [
{
"target_name": "addon",
"sources": [
"hello.cc"
]
}
]
}
$ npm install -g node-gyp
module.exports.hello = function() { return 'world'; }
$ node-gyp clean configure build
$ node-gyp rebuild # 上といっしょ
#include <node.h>
#include <v8.h>
using namespace v8;
Handle<Value> Hello(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("Hello World!"));
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("hello"),
FunctionTemplate::New(Hello)->GetFunction());
}
NODE_MODULE(addon, init) // 後ろにセミコロンいらない
var addon = require('./build/Release/addon');
console.log( addon.hello() ); // Hello World!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment