将std :: string转换为v8 :: string,反之亦然? [英] Convert std::string to v8::string and viceversa?
本文介绍了将std :: string转换为v8 :: string,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用c ++创建我的第一个节点模块.我只是想做一个简单的Hello,将我的名字作为参数传递.我发现这种方法可以将参数转换为v8 :: strings,这似乎很丑陋:
i'm trying to create my first node module in c++. I just wanted to do a simple Hello passing my name as parameter. I found this way to convert parameters to v8::strings which seems quite ugly:
Local<String> name = String::NewFromUtf8(isolate, *v8::String::Utf8Value(args[0]->ToString()));
有没有人可以建议我进行这种类型的简单投射?!我想念什么吗?!
Is there anyone who could suggest me simple way to do this sort of cast?! Am i missing something?!
推荐答案
v8的新版本也需要隔离:
Newer versions of v8 requires also isolate:
void Foo(const v8::FunctionCallbackInfo<v8::Value> &args)
{
// from v8 to cpp
v8::Isolate* isolate = args.GetIsolate();
v8::String::Utf8Value str(isolate, args[0]);
std::string cppStr(*str);
// back to v8
v8::Local<v8::String> v8String = v8::String::NewFromUtf8(isolate, cppStr.c_str(), v8::String::kNormalString);
}
这篇关于将std :: string转换为v8 :: string,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文