我有一个函数,它是一个字符串,然后传递给我的c函数add_node()
Handle<Value> Graph::add_node(const v8::Arguments& args) { HandleScope scope; Graph* graph = ObjectWrap::Unwrap<Graph>(args.This()); graph->add_node( args[0]->ToString() ); std::cout << "In add node \n"; }
但是我有麻烦,因为我的所有参数都是v8的某些或另一个,我不知道如何在两者之间切换. documentation也不清楚.
编译器给我这个错误
../graph/binding.cc:52:10: error: no matching member function for call to 'add_node' graph->add_node( args[0]->ToString() ); ~~~~~~~^~~~~~~~ ../graph/directed_graph.h:27:7: note: candidate function not viable: no known conversion from 'Local<v8::String>' to 'std::string &' (aka 'basic_string<char> &') for 1st argument; void add_node( std::string & currency );
如何在本地< v8 :: String>之间切换和std :: string&
解决方法
这似乎很好
v8::String::Utf8Value param1(args[0]->ToString()); std::string from = std::string(*param1);
如果你只是想将一个std :: string转换成一个v8 :: String,那就行了
std::string something("hello world"); Handle<Value> something_else = String::New( something.c_str() );