Ignore:
Timestamp:
07/12/16 20:22:23 (9 years ago)
Author:
epyon
Message:
  • several STL updates
  • several minor fixes
File:
1 edited

Legend:

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

    r503 r505  
    201201}
    202202
    203 shash64 nv::lua::table_guard::get_string( string_view element, string_table& table, uint64 defval /*= 0 */ )
     203nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    204204{
    205205        lua_getfield( m_state, -1, element.data() );
     
    210210        {
    211211                str = lua_tolstring( m_state, -1, &l );
    212                 result = table.insert( string_view( str, l ) );
    213         }
    214         lua_pop( m_state, 1 );
    215         return result;
    216 }
    217 
    218 nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    219 {
    220         lua_getfield( m_state, -1, element.data() );
     212                string_view sv( str, l );
     213                result = table ? table->insert( sv ) : shash64( sv );
     214        }
     215        lua_pop( m_state, 1 );
     216        return result;
     217}
     218
     219shash64 nv::lua::table_guard::get_string_hash_64( int i, uint64 defval /*= 0 */ )
     220{
     221        lua_rawgeti( m_state, -1, i );
     222        size_t l = 0;
     223        const char* str = nullptr;
     224        uint64 result = defval;
     225        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     226        {
     227                str = lua_tolstring( m_state, -1, &l );
     228                result = hash_string< uint64 >( str, l );
     229                //NV_LOG_DEBUG( str );
     230        }
     231        lua_pop( m_state, 1 );
     232        return shash64( result );
     233}
     234
     235nv::string128 nv::lua::table_guard::get_string128( int i, string_view defval /*= string_view() */ )
     236{
     237        lua_rawgeti( m_state, -1, i );
     238        size_t l = 0;
     239        const char* str = nullptr;
     240        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     241        {
     242                str = lua_tolstring( m_state, -1, &l );
     243        }
     244        else
     245        {
     246                l = defval.size();
     247                str = defval.data();
     248        }
     249        string128 result( str, l );
     250        lua_pop( m_state, 1 );
     251        return result;
     252}
     253
     254const_string nv::lua::table_guard::get_string( int i, string_view defval /*= string_view() */ )
     255{
     256        lua_rawgeti( m_state, -1, i );
     257        size_t l = 0;
     258        const char* str = nullptr;
     259        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     260        {
     261                str = lua_tolstring( m_state, -1, &l );
     262        }
     263        else
     264        {
     265                l = defval.size();
     266                str = defval.data();
     267        }
     268        const_string result( str, l );
     269        lua_pop( m_state, 1 );
     270        return result;
     271}
     272
     273shash64 nv::lua::table_guard::get_string( int i, string_table* table, uint64 defval /*= 0 */ )
     274{
     275        lua_rawgeti( m_state, -1, i );
    221276        size_t l = 0;
    222277        const char* str = nullptr;
     
    302357}
    303358
     359char nv::lua::table_guard::get_char( int i, char defval /*= ' ' */ )
     360{
     361        lua_rawgeti( m_state, -1, i );
     362        char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && nlua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval;
     363        lua_pop( m_state, 1 );
     364        return result;
     365}
     366
     367int nv::lua::table_guard::get_integer( int i, int defval /*= 0 */ )
     368{
     369        lua_rawgeti( m_state, -1, i );
     370        lua_Integer result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tointeger( m_state, -1 ) : defval;
     371        lua_pop( m_state, 1 );
     372        return static_cast<int>( result );
     373}
     374
     375unsigned nv::lua::table_guard::get_unsigned( int i, unsigned defval /*= 0 */ )
     376{
     377        lua_rawgeti( m_state, -1, i );
     378        unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? nlua_tounsigned( m_state, -1 ) : defval;
     379        lua_pop( m_state, 1 );
     380        return result;
     381}
     382
     383double nv::lua::table_guard::get_double( int i, double defval /*= 0.0 */ )
     384{
     385        lua_rawgeti( m_state, -1, i );
     386        double result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tonumber( m_state, -1 ) : defval;
     387        lua_pop( m_state, 1 );
     388        return result;
     389}
     390
     391float nv::lua::table_guard::get_float( int i, float defval /*= 0.0 */ )
     392{
     393        lua_rawgeti( m_state, -1, i );
     394        float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? static_cast<float>( lua_tonumber( m_state, -1 ) ) : defval;
     395        lua_pop( m_state, 1 );
     396        return result;
     397}
     398
     399bool nv::lua::table_guard::get_boolean( int i, bool defval /*= false */ )
     400{
     401        lua_rawgeti( m_state, -1, i );
     402        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN ? lua_toboolean( m_state, -1 ) != 0 : defval;
     403        lua_pop( m_state, 1 );
     404        return result;
     405}
     406
    304407float nv::lua::table_guard::get_float( string_view element, float defval /*= 0.0 */ )
    305408{
     
    326429}
    327430
     431bool nv::lua::table_guard::is_table( int i )
     432{
     433        lua_rawgeti( m_state, -1, i );
     434        bool result = lua_type( m_state, -1 ) == LUA_TTABLE;
     435        lua_pop( m_state, 1 );
     436        return result;
     437}
     438
     439bool nv::lua::table_guard::is_number( int i )
     440{
     441        lua_rawgeti( m_state, -1, i );
     442        bool result = lua_type( m_state, -1 ) == LUA_TNUMBER;
     443        lua_pop( m_state, 1 );
     444        return result;
     445}
     446
     447bool nv::lua::table_guard::is_boolean( int i )
     448{
     449        lua_rawgeti( m_state, -1, i );
     450        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN;
     451        lua_pop( m_state, 1 );
     452        return result;
     453}
     454
     455bool nv::lua::table_guard::is_string( int i )
     456{
     457        lua_rawgeti( m_state, -1, i );
     458        bool result = lua_type( m_state, -1 ) == LUA_TSTRING;
     459        lua_pop( m_state, 1 );
     460        return result;
     461}
     462
    328463bool nv::lua::table_guard::is_number( string_view element )
    329464{
     
    349484        return result;
    350485}
    351 
    352486
    353487bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object )
Note: See TracChangeset for help on using the changeset viewer.