Ignore:
Timestamp:
08/03/13 12:07:12 (12 years ago)
Author:
epyon
Message:
  • object - lua registration will now be manual, with an option to be separate from the type system
  • lua/state - explicit object registration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_state.cc

    r185 r187  
    303303}
    304304
     305lua::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
    305318lua::reference lua::state::register_object( object * o )
    306319{
    307         if (!o) return ref_none;
     320        if ( o == nullptr ) return ref_none;
    308321        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() );
    320326}
    321327
     
    403409        if ( !p.resolve( L, global ) )
    404410        {
    405                 lua_pop( L, 1 );
    406411                NV_LOG( LOG_ERROR, "Lua error : not a valid path - " + p.to_string() );
    407412                return false;
     
    416421        return true;
    417422}
     423
Note: See TracChangeset for help on using the changeset viewer.