Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inquiry with file node-addon-examples/5_function_factory/node_0.12/addon.cc #99

Open
J-Cake opened this issue May 30, 2019 · 6 comments

Comments

@J-Cake
Copy link

J-Cake commented May 30, 2019

Hi, anyone reading this,

The file node-addon-examples/5_function_factory/node_0.12/addon.cc contains a function factory, that's all well and good, but when I do something similiar, instead of using a global function, I'm using an instance function, (sorry, bad C++ vocab, I'm only new...) a function that's a private member of a class, and I want to use that as the function body, where the example uses

void MyFunction(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);
  args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
}

as the body. The issue is I get an error when doing this, the error is as follows: error C3867: 'Class::SampleFunction': non-standard syntax; use '&' to create a pointer to member and I have no idea what to do about it.

@mhdawson
Copy link
Member

mhdawson commented Jun 4, 2019

Sample Function would have to be a static function and you would need use the & modifier to get the address of the function. If that does not clarify it for you I think you'd need to paste the code that is not working for you.

@J-Cake
Copy link
Author

J-Cake commented Jun 4, 2019

@mhdawson Hi, I've tried everything I can think of, including this answer that shows how to do it, but unfortunately, that doesn't work either, I'm guessing because it's either outdated, or I'm just an idiot, but the error message is the same:

error C2664: 'v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate *,v8::FunctionCallback,v8::Local<v8::Value>,v8::Local<v8::Signature>,int,v8::ConstructorBehavior,v8::SideEffectType)': cannot convert argument 2 from 'v8::Local<v8::Value> (__cdecl *)(const v8::FunctionCallbackInfo<v8::Value> &)' to 'v8::FunctionCallback' 

@mhdawson
Copy link
Member

mhdawson commented Jun 5, 2019

@J-Cake do you have a link to your code and the line that it reports the error on?

@J-Cake
Copy link
Author

J-Cake commented Jun 6, 2019

@mhdawson Hi, yes, I do have an example of the code, here. The error is this:

window.cpp(25): error C2664: 'v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate *,v8::FunctionCallback,v8::Local<v8::Value>,v8::Local<v8::Signature>,int,v8::ConstructorBehavior,v8::SideEffectType)': cannot convert argument 2 from 'v8::Local<v8::Value> (__cdecl *)(const v8::FunctionCallbackInfo<v8::Value> &)' to 'v8::FunctionCallback'

It would also be worth mentioning the declaration of the BackgroundCB function in the header file:

static v8::Handle<v8::Value> BackgroundCB(const v8::FunctionCallbackInfo<v8::Value> &args);

@mhdawson
Copy link
Member

mhdawson commented Jun 6, 2019

Ok so I missed that you are not using N-API? The examples are more up to date and supported on that side of things. Can you not use N-API for some reason?

@J-Cake
Copy link
Author

J-Cake commented Jun 7, 2019

I'm not using N-API because in my opinion, it's best to learn a language/framework without additional layers of abstraction first, plus libraries in general just don't seem to work. As in, they simply won't compile.

But I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants