- Timestamp:
- 08/03/13 12:07:12 (12 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_state.cc
r185 r187 303 303 } 304 304 305 lua::reference lua::state::register_object( object * o, const char* lua_name ) 306 { 307 if ( o == nullptr ) return ref_none; 308 stack_guard guard( this ); 309 lua_getglobal( L, lua_name ); 310 if ( lua_isnil( L, -1 ) ) 311 { 312 NV_THROW( runtime_error, std::string( lua_name ) + " type not registered!" ); 313 } 314 deep_pointer_copy( -1, o ); 315 return luaL_ref( L, LUA_REGISTRYINDEX ); 316 } 317 305 318 lua::reference lua::state::register_object( object * o ) 306 319 { 307 if ( !o) return ref_none;320 if ( o == nullptr ) return ref_none; 308 321 type_database *db = o->get_root()->get_type_database(); 309 if (!db) return ref_none; 310 type_entry* t = db->get_type(typeid(o)); 311 if (!t) return ref_none; 312 stack_guard guard( this ); 313 lua_getglobal( L, t->name.c_str() ); 314 if ( lua_isnil( L, -1 ) ) 315 { 316 NV_THROW( runtime_error, std::string( t->name ) + " type not registered!" ); 317 } 318 deep_pointer_copy( -1, o ); 319 return luaL_ref( L, LUA_REGISTRYINDEX ); 322 if ( db == nullptr ) return ref_none; 323 type_entry* t = db->get_type(typeid(*o)); 324 if ( t == nullptr ) return ref_none; 325 return register_object( o, t->name.c_str() ); 320 326 } 321 327 … … 403 409 if ( !p.resolve( L, global ) ) 404 410 { 405 lua_pop( L, 1 );406 411 NV_LOG( LOG_ERROR, "Lua error : not a valid path - " + p.to_string() ); 407 412 return false; … … 416 421 return true; 417 422 } 423 -
trunk/src/object.cc
r120 r187 16 16 17 17 object::object() 18 : m_root( nullptr ), m_id(), m_name(), m_uid(0), m_lua_index( -2), m_parent( nullptr ), m_children(), m_child_count(0)18 : m_root( nullptr ), m_id(), m_name(), m_uid(0), m_lua_index(lua::ref_none), m_parent( nullptr ), m_children(), m_child_count(0) 19 19 { 20 20 } 21 21 22 22 object::object( root* aroot, const string& aid ) 23 : 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 : m_root( aroot ), m_id(aid), m_name(), m_uid( 0 ), m_lua_index(lua::ref_none), m_parent( nullptr ), m_children(), m_child_count(0) 24 24 { 25 25 if ( m_root ) 26 26 { 27 27 uid_store* store = get_root()->get_uid_store(); 28 lua::state* state = get_root()->get_lua_state();29 28 if (store) 30 29 { 31 30 m_uid = store->insert( this ); 32 }33 if (state)34 {35 m_lua_index = state->register_object( this );36 31 } 37 32 } … … 195 190 db->create_type<object>("object").fields(fields); 196 191 } 192 193 void nv::object::register_with_lua( const char* lua_name /*= nullptr*/ ) 194 { 195 lua::state* state = get_root()->get_lua_state(); 196 if (state) 197 { 198 if ( lua_name != nullptr ) 199 { 200 m_lua_index = state->register_object( this, lua_name ); 201 } 202 else 203 { 204 m_lua_index = state->register_object( this ); 205 } 206 } 207 }
Note: See TracChangeset
for help on using the changeset viewer.