2
私はC言語を新しく使い、単純なノードネイティブ拡張を行っています。私は私が見るサイトを呼び出すとここCノードネイティブエクステンションはメソッドを2回呼び出します。
はhelloworld.c
Handle<Value> Method(const Arguments& args) {
printf(":%s:\n", "Calling Method");
//SendByte(bdrate,'1');
HandleScope scope;
if(toggleLight()==0){
printf(":%s:\n", "Turning On");
return scope.Close(String::New("Turned On"));
}
else{
printf(":%s:\n", "Turning Off");
return scope.Close(String::New("Turned Off"));
}
}
void init(Handle<Object> target) {
printf(":%s:\n", "Init");
target->Set(String::NewSymbol("hello"),
FunctionTemplate::New(Method)->GetFunction());
}
NODE_MODULE(helloworld, init)
私は次のNode.jsクラスを介して、前を消費呼ばれる私の拡張機能のためのコードが...
var addon = require('./build/Release/helloworld');
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(addon.hello());
response.end();
}).listen(8888);
です私の端末では次のようになります
~/Desktop/hellonode$ node testnode
:Init:
:Calling Method:
:Turning Off:
:Calling Method:
:Turning On:
なぜ2回呼び出すように見えますか?私は答えが明らかだと確信していますが、私はそれを見ることができません。
ええと、CかC++のどちらを使用しているのか判断できますか?ここでは、.cファイルにCとC++を混在させています。ワオ。 – Griwes