Changeset 77 for trunk/src/object.cc


Ignore:
Timestamp:
06/01/13 22:47:44 (12 years ago)
Author:
epyon
Message:
  • types - typemap based on type_index, allowing type retrival by typeid
  • object - autoinitialization of uid and lua_index, based on root's capabilities
  • object - proper cleanup of uid and lua_index
  • object - root accessor
  • lua_state - implementation of register_object and unregister_object
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/object.cc

    r66 r77  
    99#include "nv/root.hh"
    1010#include "nv/types.hh"
     11#include "nv/lua/lua_state.hh"
     12#include "nv/uid.hh"
    1113
    1214using namespace nv;
     
    1921}
    2022
    21 object::object( root* aroot, const string& aid, uid auid )
    22         : m_root( aroot ), m_id(aid), m_name(), m_uid( auid ), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
     23object::object( root* aroot, const string& aid )
     24        : m_root( aroot ), m_id(aid), m_name(), m_uid( 0 ), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
    2325{
    24         //      uid_store::register_object( this, auid );
     26        if ( m_root )
     27        {
     28                uid_store*  store = get_root()->get_uid_store();
     29                lua::state* state = get_root()->get_lua_state();
     30                if (store)
     31                {
     32                        m_uid = store->insert( this );
     33                }
     34                if (state)
     35                {
     36                        m_lua_index = state->register_object( this );
     37                }
     38        }
     39
    2540}
    2641
     
    7792object::~object()
    7893{
    79 //      if ( m_lua_index != lua::ref_none )
    80 //      {
    81 //              lua::state::get()->unregister_object( this );
    82 //      }
    83 //      uid_store::unregister_object( m_uid );
     94        if ( m_lua_index != lua::ref_none )
     95        {
     96                lua::state* state = get_root()->get_lua_state();
     97                state->unregister_object( this );
     98        }
     99        if ( m_uid != 0 && m_root )
     100        {
     101                uid_store* store = get_root()->get_uid_store();
     102                if (store) store->remove( m_uid );
     103        }
    84104        detach();
    85105        destroy_children();
Note: See TracChangeset for help on using the changeset viewer.