从另一个Nan :: ObjectWrap返回Nan :: ObjectWrap [英] Return a Nan::ObjectWrap from another Nan::ObjectWrap

查看:235
本文介绍了从另一个Nan :: ObjectWrap返回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的方法实例中返回. >

注意:我没有经验,所以这可能有错误或错误.我把我的资料放在方括号中,我想是例子的完成方式.

  1. 在接收其自身的指针的第一个类中创建static NewInstance方法( 解决方案

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.

  1. Create static NewInstance method in a first class which receives pointer of itself (NewInstance)
  2. Use v8::External to wrap first class' C++ object and pass it as an argument for New with argc and argv to first class' constructor (using v8::External) (v8::External doc)
  3. Edit first class' New method and handle info.Length() == 1 && info[0]->IsExternal() case which is basically copy constructor in this case (copying passed pointer)
  4. Use ...::NewInstance() in second class to set return value

这篇关于从另一个Nan :: ObjectWrap返回Nan :: ObjectWrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆