John Smith John Smith - 2 months ago 10
C++ Question

Pass arguments to another function

Here I assign one Argument to the Handler:

const unsigned argc = 1;
v8::Local<v8::Value> argv[1] = { NanNew("hello world") };

NanMakeCallback(NanGetCurrentContext()->Global(), callHandle, argc, argv);


It works

But I want to assign two parameters! That is why I tried to do:

const unsigned argc = 2;
v8::Local<v8::Value> argv[1] = { NanNew("hello world") };
argv[2] = { NanNew("second argument") };

NanMakeCallback(NanGetCurrentContext()->Global(), callbackHandle, argc, argv);


But then I get this error:

functions.cc:97:18: error: expected expression
argv[2] << { NanNew("second argument") };
^


What do I wrong? How can I assign two Arguments? Thanks

Answer

You seem to be creating an array of size 1:

v8::Local<v8::Value> argv[1] = { NanNew("hello world") };

Then trying to assign { NanNew("second argument") }; to its element with index 2. This won't work. Did you mean something like this:

v8::Local<v8::Value> argv[2] = { NanNew("hello world"), NanNew("second arg") };

?

Comments