歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Node.js調用C++的要點

Node.js調用C++的要點

日期:2017/3/1 10:07:42   编辑:Linux編程

1.如何將js的字符串轉化為C++的字符串

const char* ToCString(const String::Utf8Value& value)
{
return *value ? *value: "string conversion failed";
}
Handle<Value>Open(const Arguments&args)
{
HandleScope scope;
String::Utf8Value str(args[0]);//
const char * pstr = ToCString(str);
Handle<Boolean>b = Boolean::New(bRet);
return scope.Close(b);
}
2.基本類型
int i;
Handle<Number> num = Number::New(i)
bool b;
Handle<Boolean>b = Boolean::New(bRet);

//數組

Handle<Array> array =Array::New(10);
Local<Object> obj = Object::New();//對象
obj->Set(String::NewSymbol("hello"),String::New("World"));
array->Set(0,obj);

Copyright © Linux教程網 All Rights Reserved