Changeset 265 for trunk/src


Ignore:
Timestamp:
06/19/14 02:22:56 (11 years ago)
Author:
epyon
Message:
  • lua::ref lightweight wrapper class
  • allows distinction from int for templates
Location:
trunk/src
Files:
1 deleted
5 edited

Legend:

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

    r263 r265  
    233233}
    234234
    235 void nv::lua::register_map_area_instance( lua_State* L, int object_index, map_area* area )
    236 {
    237         lua_rawgeti( L, LUA_REGISTRYINDEX, object_index );
     235void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area )
     236{
     237        lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() );
    238238        lua_pushstring( L, "__map_area_ptr" );
    239239        lua_pushlightuserdata( L, (map_area*)area );
  • trunk/src/lua/lua_state.cc

    r263 r265  
    328328}
    329329
    330 lua::reference lua::state::register_object( void* o, const char* lua_name )
    331 {
    332         if ( o == nullptr ) return ref_none;
     330lua::ref lua::state::register_object( void* o, const char* lua_name )
     331{
     332        if ( o == nullptr ) return lua::ref( lua::ref::none );
    333333        stack_guard guard( this );
    334334        lua_getglobal( m_state, lua_name );
     
    338338        }
    339339        deep_pointer_copy( -1, o );
    340         return luaL_ref( m_state, LUA_REGISTRYINDEX );
    341 }
    342 
    343 lua::reference lua::state::register_proto( const char* id, const char* storage )
     340        return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) );
     341}
     342
     343lua::ref lua::state::register_proto( const char* id, const char* storage )
    344344{
    345345        stack_guard guard( this );
     
    354354                NV_THROW( runtime_error, std::string( id ) + " not found in " + std::string( storage ) + " storage!" );
    355355        }
    356         return luaL_ref( m_state, LUA_REGISTRYINDEX );
     356        return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) );
    357357}
    358358
     
    369369}
    370370
    371 void lua::state::unregister_object( reference object_index )
    372 {
    373         if ( object_index == ref_nil ) return;
     371void lua::state::unregister_object( ref object_index )
     372{
     373        if ( !object_index.is_valid() ) return;
    374374        stack_guard guard( this );
    375         lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
     375        lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() );
    376376        lua_pushstring( m_state, "__ptr" );
    377377        lua_pushboolean( m_state, false );
    378378        lua_rawset( m_state, -3 );
    379379        lua_pop( m_state, 1 );
    380         luaL_unref( m_state, LUA_REGISTRYINDEX, object_index );
     380        luaL_unref( m_state, LUA_REGISTRYINDEX, object_index.get() );
    381381}
    382382
     
    419419}
    420420
    421 void nv::lua::state::store_metadata( reference object_index, const std::string& metaname, void* pointer )
    422 {
    423         if ( object_index == ref_nil ) return;
    424         lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
     421void nv::lua::state::store_metadata( ref object_index, const std::string& metaname, void* pointer )
     422{
     423        if ( !object_index.is_valid() ) return;
     424        lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() );
    425425        lua_pushstring( m_state, metaname.c_str() );
    426426        lua_pushlightuserdata( m_state, pointer );
  • trunk/src/lua/lua_values.cc

    r262 r265  
    4040}
    4141
     42void nv::lua::detail::push_nil( lua_State *L )
     43{
     44        lua_pushnil( L );
     45}
     46
    4247void nv::lua::detail::push_unsigned( lua_State *L, lunsigned v )
    4348{
     
    7479        lua_pushlightuserdata( L, p );
    7580}
     81
     82void nv::lua::detail::push_ref_object ( lua_State *L, ref object )
     83{
     84        lua_rawgeti( L, LUA_REGISTRYINDEX, object.get() );
     85}
     86
    7687
    7788lunsigned   nv::lua::detail::to_unsigned( lua_State *L, int index )
  • trunk/src/object.cc

    r257 r265  
    1818        , m_name()
    1919        , m_uid(0)
    20         , m_lua_index(lua::ref_none)
    21         , m_lua_proto_index(lua::ref_none)
     20        , m_lua_index(lua::ref::none)
     21        , m_lua_proto_index(lua::ref::none)
    2222        , m_parent( nullptr )
    2323        , m_children()
  • trunk/src/root.cc

    r264 r265  
    2222        destroy_children( o );
    2323        o->detach();
    24         if ( m_lua_state && o->m_lua_index != lua::ref_none )
     24        if ( m_lua_state && o->m_lua_index != lua::ref::none )
    2525        {
    26                 m_lua_state->unregister_object( o->m_lua_index );
     26                m_lua_state->unregister_object( lua::ref( o->m_lua_index ) );
    2727        }
    2828        if ( m_uid_store && o->m_uid != 0 )
     
    4747                if ( lua_name != nullptr )
    4848                {
    49                         o->m_lua_index       = m_lua_state->register_object( o, lua_name );
     49                        o->m_lua_index       = m_lua_state->register_object( o, lua_name ).get();
    5050                }
    5151                if ( storage != nullptr )
    5252                {
    53                         o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage );
     53                        o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage ).get();
    5454                }
    5555        }
Note: See TracChangeset for help on using the changeset viewer.