我正在尝试将字符串传递给 Node.js 中的 C++ 插件。我正在使用 Nan 图书馆,这似乎是推荐的。对于具有数字的等效任务,我执行以下操作:
NAN_METHOD(funcName) {
if (!info[0]->IsUint32()) {
Nan::ThrowError("Argument must be an unsigned int 32");
}
v8::Local<v8::Context> ctxt = info.GetIsolate()->GetCurrentContext();
uint32_t blocks;
info[0]->Uint32Value(ctxt).To(&blocks);
}
之后我可以使用blocks变量。似乎没有任何等效StringValue功能。我已经尝试过info[0]->ToString(ctxt),但这给了我一个MaybeLocal似乎是一个空检查local。一旦我转换为v8::Local<v8::String>我不知道如何实际访问字符串值。我也尝试过info[0]->Cast,但这也不起作用。任何帮助,将不胜感激。