Skip to content

Commit

Permalink
Support passing shared pointers from JavaScript to C++ on Node.js tar…
Browse files Browse the repository at this point in the history
…get.

Might fix issue #26.
  • Loading branch information
jjrv committed Jul 29, 2016
1 parent c44f55f commit e8eb4e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/nbind/v8/BindWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class BindWrapper : public node::ObjectWrap {
this->Wrap(args.This());
}

Bound *getBound() { return(bound.get()); }
inline std::shared_ptr<Bound> getShared() { return(bound); }

inline Bound *getBound() { return(bound.get()); }

#if !defined(DUPLICATE_POINTERS)

Expand Down
19 changes: 19 additions & 0 deletions include/nbind/v8/BindingType.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ struct BindingType<ArgType *> {

};

template <typename ArgType>
struct BindingType<std::shared_ptr<ArgType>> {

typedef std::shared_ptr<ArgType> Type;

static inline bool checkType(WireType arg) {
// TODO: Also check type of object!
return(arg->IsObject());
}

static inline Type fromWireType(WireType arg) {
v8::Local<v8::Object> argWrapped = arg->ToObject();
return(node::ObjectWrap::Unwrap<BindWrapper<ArgType>>(argWrapped)->getShared());
}

static inline WireType toWireType(Type arg);

};

template <typename ArgType>
struct BindingType<NullableType<ArgType>> {

Expand Down

0 comments on commit e8eb4e6

Please sign in to comment.