没有合适的构造函数可从“ v8 :: Array *”转换为“ v8 :: Local <v8 :: Array>”

问题描述

我试图将传递给我的C ++插件的参数转换为数组,但是遇到标题错误。这是我的代码

#include "node.h"
#include "node_buffer.h"
#include "v8.h"

using namespace v8;
using namespace std;

namespace water{
    using v8::FunctionCallbackInfo;
    using v8::Isolate;
    using v8::Local;
    using v8::Object;
    using v8::String;
    using v8::Number;
    using v8::Value;
    using v8::Array;

    void water(const FunctionCallbackInfo<Value> &args)
    {
        if(args[0]->IsArray())
        {
           Local<Array> a = Array::Cast(*args[0]);
           Local<Array> b = Array::Cast(*args[1]);
        }
        args.GetReturnValue().Set(20);
    }
    }

这是我的错误no suitable constructor exists to convert from “v8::Array *” to “v8::Local<v8::Array>”

换句话说,我希望使用node-gyp从NodeJs程序中将数组传递给我的方法,但我似乎做不到。

解决方法

我认为应该读the documentation

Local<Array> a = args[0].As<Array>();