1

I am trying to cast the arguments passed to my C++ addon into arrays but I am running into the error in the title. This is my code:

#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);
    }
    }

This is my error no suitable constructor exists to convert from “v8::Array *” to “v8::Local<v8::Array>”

In other words, I am looking to pass in arrays to my method from a NodeJs program using node-gyp but I can't seem to do so.

Botje
  • 26,269
  • 3
  • 31
  • 41
RDK961
  • 41
  • 6
  • `**Local a ` -- Do not put stars in the code to denote emphasis. A star could easily be confused for a pointer dereference, multiplication, or other places where asterisks are used in the code. Second, this looks like an [XY Problem](http://xyproblem.info/). – PaulMcKenzie Aug 10 '20 at 17:42

1 Answers1

2

Reading the documentation, I think it should be

Local<Array> a = args[0].As<Array>();
Botje
  • 26,269
  • 3
  • 31
  • 41