从另一个Nan :: ObjectWrap返回Nan :: ObjectWrap [英] Return a Nan::ObjectWrap from another Nan::ObjectWrap
问题描述
我有两个Nan::ObjectWrap
class Zyre: public Nan::ObjectWrap {...}
class ZyreEvent: public Nan::ObjectWrap {...}
如何从Zyre
中的方法返回ZyreEvent
javascript对象?
我有以下方法,可在其中创建一个ZyreEvent
:
NAN_METHOD (Zyre::_recv) {
Zyre *node = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
ZyreEvent *zyre_event = new ZyreEvent (node->self);
info.GetReturnValue().Set(zyre_event->Wrap(info.This()));
}
但是我不能包装zyre_event,因为Wrap
是受保护的成员.
如果我正确理解,您想从Nan::ObjectWrap
的(子类)的另一个Nan::ObjectWrap
的方法实例中返回. >
注意:我没有经验,所以这可能有错误或错误.我把我的资料放在方括号中,我想是例子的完成方式.
- 在接收其自身的指针的第一个类中创建
static NewInstance
方法(使用v8 :: External )(复制传递的指针) - 在第二类中使用
...::NewInstance()
设置返回值
I have two subclasses of Nan::ObjectWrap
class Zyre: public Nan::ObjectWrap {...}
class ZyreEvent: public Nan::ObjectWrap {...}
How can I return a ZyreEvent
javascript object from a method in Zyre
?
I have the following method, in which I create a ZyreEvent
:
NAN_METHOD (Zyre::_recv) {
Zyre *node = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
ZyreEvent *zyre_event = new ZyreEvent (node->self);
info.GetReturnValue().Set(zyre_event->Wrap(info.This()));
}
But I can't Wrap the zyre_event because Wrap
is a protected member.
If I understand correctly, you want to return from (subclass of) Nan::ObjectWrap
's method instance of another (subclass of) Nan::ObjectWrap
.
Note: I'm not experienced so this may have faults or be wrong. I've put my sources in brackets where are examples how it's is done I guess.
- Create
static NewInstance
method in a first class which receives pointer of itself (NewInstance) - Use
v8::External
to wrap first class' C++ object and pass it as an argument forNew
withargc
andargv
to first class' constructor (using v8::External) (v8::External doc) - Edit first class'
New
method and handleinfo.Length() == 1 && info[0]->IsExternal()
case which is basically copy constructor in this case (copying passed pointer) - Use
...::NewInstance()
in second class to set return value
这篇关于从另一个Nan :: ObjectWrap返回Nan :: ObjectWrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!