Javascript C节点本机扩展两次调用方法
因此,我对C相当陌生,正在研究一个简单的节点本机扩展 下面是我的扩展名helloworld.c的代码Javascript C节点本机扩展两次调用方法,javascript,c++,c,node.js,Javascript,C++,C,Node.js,因此,我对C相当陌生,正在研究一个简单的节点本机扩展 下面是我的扩展名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")
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)
当我呼叫该站点时,我在终端中看到以下内容
~/Desktop/hellonode$ node testnode
:Init:
:Calling Method:
:Turning Off:
:Calling Method:
:Turning On:
为什么它似乎要调用该方法两次?我确信答案是显而易见的,但我看不到。这有点重复。这不是扩展中的错误,而是HTTP代码中的问题 见:
<>基本上,你的浏览器请求两个URL,即代码>/< /COD>和
~/Desktop/hellonode$ node testnode
:Init:
:Calling Method:
:Turning Off:
:Calling Method:
:Turning On: