【问题标题】:How to access Local<String> in a node.js AddOn如何在 node.js 插件中访问 Local<String>
【发布时间】:2016-02-19 09:49:48
【问题描述】:

我为 node.js 编写了一个插件,我想在其中使用传递给我的 c++ 代码的参数。

void tdlNodeAddOnClass::my_func( const FunctionCallbackInfo<Value>& args)
{
  Isolate* isolate = args.GetIsolate();

  if ( args[0]->IsString() )
  {
    Local<String> Value = args[0]->ToString();
  }
}

如何访问实际的 c 样式缓冲区? 有没有比 v5.6.0 文档更好的文档或教程?

【问题讨论】:

    标签: javascript c++ node.js node.js-addon


    【解决方案1】:

    你可以这样使用:

    Isolate* isolate = args.GetIsolate();
    if (args[0]->IsString()) {
      Local<String> val = args[0]->ToString();
      Utf8Value str(isolate, val);
    }
    

    然后您可以通过 *str 访问底层 char *

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多