Changeset 440 for trunk/src/lua


Ignore:
Timestamp:
07/23/15 21:16:01 (10 years ago)
Author:
epyon
Message:
  • massive std::string removal
  • no header depends on std::string anymore (or any other STL header)
  • still some code files do (WIP)
  • massive refactoring where std::string was used
  • lua still messy (grep for string128 - used everywhere)
  • string_twine added
Location:
trunk/src/lua
Files:
5 edited

Legend:

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

    r433 r440  
    2121        {
    2222                lua_pop( L, 1 );
    23                 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string().c_str() );
     23                NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() );
    2424        }
    2525
     
    2727        {
    2828                lua_pop( L, 1 );
    29                 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string().c_str() );
     29                NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() );
    3030        }
    3131        m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
     
    6464        if ( status != 0 )
    6565        {
    66                 std::string error = lua_tostring( L, -1 );
     66                string128 error( nlua_tostringview( L, -1 ) );
    6767                lua_pop( L, 1 );
    68                 NV_LUA_ABORT( "function_base::call", "call failed - ", error.c_str() );
     68                NV_LUA_ABORT( "function_base::call", "call failed - ", error );
    6969        }
    7070}
  • trunk/src/lua/lua_map_tile.cc

    r433 r440  
    1616#include "nv/lua/lua_values.hh"
    1717#include "nv/lua/lua_raw.hh"
     18
     19// TODO: REMOVE
     20#include <string>
    1821
    1922static const char* NLUA_MAP_TILE_METATABLE = "map_tile";
  • trunk/src/lua/lua_path.cc

    r435 r440  
    7474}
    7575
    76 std::string nv::lua::path::to_string() const
     76string128 nv::lua::path::to_string() const
    7777{
    78         char buffer[64];
    79         char* start   = buffer;
    80         char* current = buffer;
     78        string128 buffer;
    8179        bool dot = false;
    82         bool oos = false;
    8380        for ( const element& e : m_elements )
    8481        {
    85                 if ( current - start > 48 ) { oos = true; break; }
    86                 if ( dot ) *current++ = '.';
     82                if ( dot ) buffer.append( "." );
    8783                if ( e.length == 0 )
    8884                {
    89                         *current++ = '[';
    90                         current += uint32_to_buffer( array_ref< char >( current, current - start ), e.value );
    91                         *current++ = ']';
     85                        buffer.append( "["_ls + e.value + "]"_ls );
    9286                        dot = false;
    9387                }
    9488                else
    9589                {
    96                         if ( size_t(current - start) + e.length > 60 ) { oos = true; break; }
    97                         nvmemcpy( current, e.str, e.length );
    98                         current += e.length;
     90                        buffer.append( e.str, e.length );
    9991                        dot = true;
    10092                }
    10193        }
    102         if (oos)
    103         {
    104                 *current++ = '.';
    105                 *current++ = '.';
    106                 *current++ = '.';
    107         }
    108         *current++ = '\0';
    109         return std::string( buffer, size_t(current - start - 1) );
     94        return buffer;
    11095}
  • trunk/src/lua/lua_state.cc

    r437 r440  
    116116        if ( !p.resolve( m_state, global ) )
    117117        {
    118                 NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string().c_str() );
     118                NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string() );
    119119                return false;
    120120        }
     
    123123        {
    124124                lua_pop( m_state, 1 );
    125                 NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string().c_str() );
     125                NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string() );
    126126                return false;
    127127        }
     
    212212        lua_pop( m_state, 1 );
    213213        return shash64( result );
    214 }
    215 
    216 std::string lua::table_guard::get_std_string( string_view element, string_view defval /*= string_view() */ )
    217 {
    218         lua_getfield( m_state, -1, element.data() );
    219         size_t l = 0;
    220         const char* str = nullptr;
    221         if ( lua_type( m_state, -1 ) == LUA_TSTRING )
    222         {
    223                 str = lua_tolstring( m_state, -1, &l );
    224         }
    225         else
    226         {
    227                 l = defval.size();
    228                 str = defval.data();
    229         }
    230         std::string result( str, l );
    231         lua_pop( m_state, 1 );
    232         return result;
    233214}
    234215
     
    250231        lua_pop( m_state, 1 );
    251232        return result;
     233}
     234
     235string128 lua::table_guard::get_string128( string_view element, string_view defval )
     236{
     237        lua_getfield( m_state, -1, element.data() );
     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;
    252252}
    253253
  • trunk/src/lua/lua_values.cc

    r399 r440  
    6565}
    6666
    67 void nv::lua::detail::push_string  ( lua_State *L, const std::string& s )
    68 {
    69         lua_pushlstring( L, s.c_str(), s.size() );
    70 }
    71 
    7267void nv::lua::detail::push_cstring ( lua_State *L, const char* s )
    7368{
     
    109104{
    110105        return lua_toboolean( L, index ) != 0;
    111 }
    112 
    113 std::string nv::lua::detail::to_string  ( lua_State *L, int index )
    114 {
    115         size_t length = 0;
    116         const char* result = lua_tolstring( L, index, &length );
    117         return std::string( result, length );
    118106}
    119107
     
    171159}
    172160
    173 std::string nv::lua::detail::to_string  ( lua_State *L, int index, const std::string& def )
     161nv::string_view nv::lua::detail::to_string_view( lua_State *L, int index, string_view def )
    174162{
    175         return ( lua_type( L, index ) == LUA_TSTRING ? lua_tostring( L, index ) : def );
     163        return ( lua_type( L, index ) == LUA_TSTRING ? nlua_tostringview( L, index ) : def );
    176164}
    177165
Note: See TracChangeset for help on using the changeset viewer.