Changeset 263 for trunk/src


Ignore:
Timestamp:
06/19/14 00:26:00 (11 years ago)
Author:
epyon
Message:
  • cleaned up sneaky lua map_area registration
Location:
trunk/src/lua
Files:
2 edited

Legend:

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

    r207 r263  
    5454nv::map_area* nv::lua::detail::to_map_area( lua_State* L, int index )
    5555{
    56         if ( lua_type( L, index ) == LUA_TTABLE )
    57         {
    58                 nv::map_area* o = nullptr;
    59                 if ( lua_istable( L , index ) )
     56        nv::map_area* o = nullptr;
     57        if ( lua_istable( L , index ) )
     58        {
     59                lua_pushstring( L, "__map_area_ptr" );
     60                lua_rawget( L, index );
     61                if ( lua_isuserdata( L, -1 ) )
    6062                {
    61                         lua_pushstring( L, "__map_area_ptr" );
    62                         lua_rawget( L, index );
    63                         if ( lua_isuserdata( L, -1 ) )
    64                         {
    65                                 o = static_cast<nv::map_area*>( lua_touserdata( L, -1 ) );
    66                         }
    67                         lua_pop( L, 1 );
    68                 }
    69                 return o;
     63                        o = static_cast<nv::map_area*>( lua_touserdata( L, -1 ) );
     64                }
     65                lua_pop( L, 1 );
    7066        }
    7167        else
     
    7369                return *(nv::map_area**)luaL_checkudata( L, index, NLUA_MAP_AREA_METATABLE );
    7470        }
     71        return o;
    7572}
    7673
     
    235232        luaopen_map_area(L);
    236233}
     234
     235void nv::lua::register_map_area_instance( lua_State* L, int object_index, map_area* area )
     236{
     237        lua_rawgeti( L, LUA_REGISTRYINDEX, object_index );
     238        lua_pushstring( L, "__map_area_ptr" );
     239        lua_pushlightuserdata( L, (map_area*)area );
     240        lua_rawset( L, -3 );
     241        lua_pop( L, 1 );
     242}
  • trunk/src/lua/lua_state.cc

    r262 r263  
    422422{
    423423        if ( object_index == ref_nil ) return;
    424         stack_guard guard( this );
    425424        lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
    426425        lua_pushstring( m_state, metaname.c_str() );
Note: See TracChangeset for help on using the changeset viewer.