source: trunk/src/root.cc @ 264

Last change on this file since 264 was 264, checked in by epyon, 11 years ago
  • decoupling - root doesn't have to be an object
  • decoupling - gui::environment doesn't need a root object at all
File size: 1.2 KB
RevLine 
[256]1// Copyright (C) 2012-2014 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/root.hh"
8
9#include "nv/uid.hh"
10#include "nv/lua/lua_state.hh"
11
12void nv::root::object_created( object* o )
13{
14        if ( m_uid_store )
15        {
16                o->m_uid = m_uid_store->insert( o );
17        }
18}
19
[257]20void nv::root::destroy_object( object* o )
[256]21{
[257]22        destroy_children( o );
23        o->detach();
[256]24        if ( m_lua_state && o->m_lua_index != lua::ref_none )
25        {
[262]26                m_lua_state->unregister_object( o->m_lua_index );
[256]27        }
28        if ( m_uid_store && o->m_uid != 0 )
29        {
30                m_uid_store->remove( o->m_uid );
31        }
[264]32        delete o;
[256]33}
[257]34
35void nv::root::destroy_children( object* o )
36{
37        while ( !o->m_children.empty() )
38        {
39                destroy_object( o->m_children.front() );
40        }
41}
42
43void nv::root::register_with_lua( object* o, const char* lua_name, const char* storage )
44{
45        if ( m_lua_state )
46        {
47                if ( lua_name != nullptr )
48                {
49                        o->m_lua_index       = m_lua_state->register_object( o, lua_name );
50                }
51                if ( storage != nullptr )
52                {
[262]53                        o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage );
[257]54                }
55        }
56
57}
58
Note: See TracBrowser for help on using the repository browser.