- Timestamp:
- 06/01/13 22:47:44 (12 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/gui_element.cc
r69 r77 13 13 14 14 element::element( root* aroot, const rectangle r ) 15 : object( aroot, "" , 0), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true )15 : object( aroot, "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ) 16 16 { 17 17 -
trunk/src/lua/lua_state.cc
r74 r77 10 10 #include "nv/logging.hh" 11 11 #include "nv/string.hh" 12 #include "nv/root.hh" 13 #include "nv/types.hh" 12 14 13 15 using namespace nv; … … 286 288 } 287 289 288 290 lua::reference lua::state::register_object( object * o ) 291 { 292 if (!o) return ref_none; 293 type_database *db = o->get_root()->get_type_database(); 294 if (!db) return ref_none; 295 type_entry* t = db->get_type(typeid(o)); 296 if (!t) return ref_none; 297 stack_guard guard( this ); 298 lua_getglobal( L, t->name.text ); 299 if ( lua_isnil( L, -1 ) ) 300 { 301 NV_THROW( runtime_error, std::string( t->name.text ) + " type not registered!" ); 302 } 303 deep_pointer_copy( -1, o ); 304 return luaL_ref( L, LUA_REGISTRYINDEX ); 305 } 306 307 void lua::state::unregister_object( object * o ) 308 { 309 if (!o) return; 310 stack_guard guard( this ); 311 lua_rawgeti( L, LUA_REGISTRYINDEX, o->get_lua_index() ); 312 lua_pushstring( L, "__ptr" ); 313 lua_pushboolean( L, false ); 314 lua_rawset( L, -3 ); 315 lua_pop( L, 1 ); 316 luaL_unref( L, LUA_REGISTRYINDEX, o->get_lua_index() ); 317 } 318 319 void lua::state::deep_pointer_copy( int index, void* obj ) 320 { 321 index = lua_absindex( L, index ); 322 lua_newtable( L ); 323 lua_pushnil( L ); 324 bool has_functions = false; 325 bool has_metatable = false; 326 327 while ( lua_next( L, index ) != 0 ) 328 { 329 if ( lua_isfunction( L, -1 ) ) 330 has_functions = true; 331 else if ( lua_istable( L, -1 ) ) 332 { 333 deep_pointer_copy( -1, obj ); 334 lua_insert( L, -2 ); 335 lua_pop( L, 1 ); 336 } 337 lua_pushvalue( L, -2 ); 338 lua_insert( L, -2 ); 339 lua_settable( L, -4 ); 340 } 341 342 if ( lua_getmetatable( L, -2 ) ) 343 { 344 lua_setmetatable( L, -2 ); 345 has_metatable = true; 346 } 347 348 if ( has_functions || has_metatable ) 349 { 350 lua_pushstring( L, "__ptr" ); 351 lua_pushlightuserdata( L, obj ); 352 lua_rawset( L, -3 ); 353 } 354 } -
trunk/src/object.cc
r66 r77 9 9 #include "nv/root.hh" 10 10 #include "nv/types.hh" 11 #include "nv/lua/lua_state.hh" 12 #include "nv/uid.hh" 11 13 12 14 using namespace nv; … … 19 21 } 20 22 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)23 object::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) 23 25 { 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 25 40 } 26 41 … … 77 92 object::~object() 78 93 { 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 } 84 104 detach(); 85 105 destroy_children();
Note: See TracChangeset
for help on using the changeset viewer.