1 // Expose C++ objects to Nasal as ghosts
3 // Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 //--------------------------------------------------------------------------
26 GhostMetadata::DestroyList GhostMetadata::_destroy_list;
28 //--------------------------------------------------------------------------
29 void GhostMetadata::addNasalBase(const naRef& parent)
31 assert( naIsHash(parent) );
32 _parents.push_back(parent);
35 //--------------------------------------------------------------------------
36 bool GhostMetadata::isInstance(naGhostType* ghost_type, bool& is_weak) const
38 if( ghost_type == _ghost_type_strong_ptr )
44 if( ghost_type == _ghost_type_weak_ptr )
53 //--------------------------------------------------------------------------
54 GhostMetadata::GhostMetadata( const std::string& name,
55 const naGhostType* ghost_type_strong,
56 const naGhostType* ghost_type_weak ):
58 _name_weak(name + " (weak ref)"),
59 _ghost_type_strong_ptr(ghost_type_strong),
60 _ghost_type_weak_ptr(ghost_type_weak)
65 //--------------------------------------------------------------------------
66 void GhostMetadata::addDerived(const GhostMetadata* derived)
71 //--------------------------------------------------------------------------
72 naRef GhostMetadata::getParents(naContext c)
74 return nasal::to_nasal(c, _parents);
76 } // namespace internal
78 //----------------------------------------------------------------------------
79 void ghostProcessDestroyList()
81 using internal::GhostMetadata;
82 typedef GhostMetadata::DestroyList::const_iterator destroy_iterator;
83 for( destroy_iterator it = GhostMetadata::_destroy_list.begin();
84 it != GhostMetadata::_destroy_list.end();
86 it->first(it->second);
87 GhostMetadata::_destroy_list.clear();