return nasal::Ghost<T>::create(c, ptr);
}
+/**
+ * Convert nasal ghosts/hashes to shared pointer (of a ghost)
+ */
+template<class T>
+typename boost::enable_if<
+ nasal::internal::has_element_type<
+ typename nasal::internal::reduced_type<T>::type
+ >,
+ T
+>::type
+from_nasal_helper(naContext c, naRef ref, const T*)
+{
+ return nasal::Ghost<T>::fromNasal(c, ref);
+}
+
#endif /* SG_NASAL_GHOST_HXX_ */
};
typedef boost::shared_ptr<Base> BasePtr;
+typedef std::vector<BasePtr> BaseVec;
struct DoubleDerived2:
public Derived
{
const BasePtr& getBase() const{return _base;}
BasePtr _base;
+ BaseVec doSomeBaseWork(const BaseVec& v) { return v; }
};
typedef boost::shared_ptr<Derived> DerivedPtr;
.bases<DerivedPtr>();
Ghost<DoubleDerived2Ptr>::init("DoubleDerived2Ptr")
.bases< Ghost<DerivedPtr> >()
- .member("base", &DoubleDerived2::getBase);
+ .member("base", &DoubleDerived2::getBase)
+ .method("doIt", &DoubleDerived2::doSomeBaseWork);
nasal::to_nasal(c, DoubleDerived2Ptr());
derived_obj.set("parents", parents2);
VERIFY( Ghost<BasePtr>::fromNasal(c, derived_obj.get_naRef()) == d3 );
+ std::vector<naRef> nasal_objects;
+ nasal_objects.push_back( Ghost<BasePtr>::create(c, d) );
+ nasal_objects.push_back( Ghost<BasePtr>::create(c, d2) );
+ nasal_objects.push_back( Ghost<BasePtr>::create(c, d3) );
+ naRef obj_vec = to_nasal(c, nasal_objects);
+
+ std::vector<BasePtr> objects = from_nasal<std::vector<BasePtr> >(c, obj_vec);
+ VERIFY( objects[0] == d );
+ VERIFY( objects[1] == d2 );
+ VERIFY( objects[2] == d3 );
+
// TODO actually do something with the ghosts...
//----------------------------------------------------------------------------