Domanda

I followed the instruction of node.js to implement factory wrapped objects.
So far it works. But what I dont get to work is a function without a return value.
I.e.: (extension of the example in the link)
In myObject.h:

tpl->PrototypeTemplate()->Set(String::NewSymbol("some"),
  FunctionTemplate::New(something)->GetFunction());

static void something (const v8::Arguments& args);

and in myObject.cc

void MyObject::something(const Arguments& args) {
  .. something without return value ...
}

does not work. Why?

I get the following errors:

error: invalid conversion from ‘void (*)(const v8::Arguments&)’ to ‘v8::InvocationCallback {aka v8::Handle<v8::Value> (*)(const v8::Arguments&)}’ [-fpermissive]
error: initializing argument 1 of ‘static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::InvocationCallback, v8::Handle<v8::Value>,  v8::Handle<v8::Signature>)’ [-fpermissive]

do i really need a return value? i mean i coud return null and ignore it, not a problem but thats not really a nice solution.

È stato utile?

Soluzione

The error is because FunctionTemplate::New() expects an InvocationCallback, which has a return type of Handle<Value>.

So, you'll have to return something, but it can simply be Undefined():

Handle<Value> MyObject::something(const Arguments& args) {
    HandleScope scope;
    return scope.Close(Undefined());
}

This makes it equivalent to:

function something() {}

Which has an implicit return; (or return undefined;).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top