+ static bool isBaseOf(naGhostType* ghost_type)
+ {
+ if( !ghost_type )
+ return false;
+
+ return getSingletonPtr()->GhostMetadata::isBaseOf(ghost_type);
+ }
+
+ static bool isBaseOf(naRef obj)
+ {
+ return isBaseOf( naGhost_type(obj) );
+ }
+
+ /**
+ * Convert Nasal object to C++ object. To get a valid object the passed
+ * Nasal objects has to be derived class of the target class (Either
+ * derived in C++ or in Nasal using a 'parents' vector)
+ */
+ static pointer fromNasal(naContext c, naRef me)
+ {
+ // Check if it's a ghost and if it can be converted
+ if( isBaseOf( naGhost_type(me) ) )
+ return Ghost::getPtr( naGhost_ptr(me) );
+
+ // Now if it is derived from a ghost (hash with ghost in parent vector)
+ else if( naIsHash(me) )
+ {
+ naRef na_parents = naHash_cget(me, const_cast<char*>("parents"));
+ if( !naIsVector(na_parents) )
+ {
+ SG_LOG(SG_NASAL, SG_DEBUG, "Missing 'parents' vector for ghost");
+ return pointer();
+ }
+
+ typedef std::vector<naRef> naRefs;
+ naRefs parents = from_nasal<naRefs>(c, na_parents);
+ for( naRefs::const_iterator parent = parents.begin();
+ parent != parents.end();
+ ++parent )
+ {
+ pointer ptr = fromNasal(c, *parent);
+ if( ptr )
+ return ptr;
+ }
+ }
+
+ return pointer();
+ }
+