尝试向数组中添加值时,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 (将#修改为@)