Created
July 26, 2014 16:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"targets": [ | |
{ | |
"target_name": "addon", | |
"sources": [ | |
"hello.cc" | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g node-gyp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.hello = function() { return 'world'; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node-gyp clean configure build | |
$ node-gyp rebuild # 上といっしょ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) // 後ろにセミコロンいらない |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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