微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试向数组中添加值时,C ++节点插件Set不起作用

如何解决尝试向数组中添加值时,C ++节点插件Set不起作用

我一直在为学校项目开发此节点模块,并且对Node和V8还是陌生的,当我尝试将其添加输出数组时,在构建时出现错误,并且VS Code给我一个错误在行return_arr->Set(i,Number::New(isolate,value));中的集合下方弯曲。我是否传递了错误的值?我曾尝试寻找其他代码示例,但它们似乎在做相同的事情,所以也许我在这里忽略了一些东西。

namespace node_effectivity {

void Method(const FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  if (args.Length() < 1) {
    return;
  } else if (args[0]->IsNull()) {
    return;
  } else if (args[0]->IsUndefined()) {
    return;
  } else if (!args[0]->Isstring()) {
    // This clause would catch IsNull and IsUndefined too...
    return;
  }
  // take input and convert to std::string
  v8::String::Utf8Value str(isolate,args[0]);
  std::string type1(*str);
  v8::String::Utf8Value str2(isolate,args[1]);
  std::string type2(*str2);

  // define our types in order for our chart
  string types[] = {"normal","fighting","flying","poison","ground","rock","bug","ghost","steel","fire","water","grass","electric","psychic","ice","dragon","dark","fairy","none"};
  // define variables to hold type index
  int t1,t2 = 0;
  // loop throught and find index of each given type
  for (int i = 0; i < 18; i++) {
    if (type1 == types[i])
      t1 = i;
    if (type2 == types[i])
      t2 = i;
  }

  // effectiveness array
  float effective_array[19][19] = {
      {1,1,0.5,1},{2,2,0.5},{1,2},{0,0},};

  // calculate values and return to array
  Local<Array> return_arr = Array::New(isolate,18);
  for (unsigned int i = 0; i < 18; i++) {
    Local<Object> object = Object::New(isolate);
    float value = effective_array[t1][i] * effective_array[i][t2];
    return_arr->Set(i,value));
  }
  args.GetReturnValue().Set(return_arr);
}

void Initialize(Local<Object> exports) {
  NODE_SET_METHOD(exports,"node_effectivity",Method);
}
NODE_MODULE(NODE_GYP_MODULE_NAME,Initialize);

} // namespace node_effectivity

它给我的错误是:

node_effectivity.cpp: In function void node_effectivity::Method(const v8::FunctionCallbackInfo<v8::Value>&):
../node_effectivity.cpp:79:55: warning: bool v8::Object::Set(uint32_t,v8::Local<v8::Value>) is deprecated: Use maybe version 
    [-Wdeprecated-declarations]
                 return_arr->Set(i,i));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。