Ignore:
Timestamp:
05/15/15 12:01:41 (10 years ago)
Author:
epyon
Message:
  • more string_ref changes
File:
1 edited

Legend:

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

    r360 r361  
    179179}
    180180
    181 string lua::table_guard::get_string( string_ref element, string_ref defval /*= string_ref() */ )
    182 {
    183         lua_getfield( m_state, -1, element.data() );
    184         string result( ( lua_type( m_state, -1 ) == LUA_TSTRING ) ? lua_tostring( m_state, -1 ) : defval.to_string() );
    185         lua_pop( m_state, 1 );
    186         return result;
     181string lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ )
     182{
     183        lua_getfield( m_state, -1, element.data() );
     184        size_t l = 0;
     185        const char* str = nullptr;
     186        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     187        {
     188                str = lua_tolstring( m_state, -1, &l );
     189        }
     190        else
     191        {
     192                l = defval.size();
     193                str = defval.data();
     194        }
     195        std::string result( str, l );
     196        lua_pop( m_state, 1 );
     197        return result;
     198}
     199
     200const_string lua::table_guard::get_string( string_ref element, string_ref defval /*= string_ref() */ )
     201{
     202        lua_getfield( m_state, -1, element.data() );
     203        size_t l = 0;
     204        const char* str = nullptr;
     205        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     206        {
     207                str = lua_tolstring( m_state, -1, &l );
     208        }
     209        else
     210        {
     211                l = defval.size();
     212                str = defval.data();
     213        }
     214        const_string result( str, l );
     215        lua_pop( m_state, 1 );
     216        return result;
    187217}
    188218
Note: See TracChangeset for help on using the changeset viewer.