Changeset 437 for trunk/src


Ignore:
Timestamp:
07/23/15 08:30:41 (10 years ago)
Author:
epyon
Message:
  • local updates (string removal)
Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/library.cc

    r433 r437  
    66
    77#include "nv/core/library.hh"
     8#include <string>
    89
    910#if NV_PLATFORM == NV_WINDOWS
     
    4041void library::open( string_view name )
    4142{
    42         m_name.assign( name.data(), name.size() );
     43        m_name = name;
    4344        if ( !open() )
    4445        {
     
    5152bool nv::library::try_open( string_view name )
    5253{
    53         m_name.assign( name.data(), name.size() );
     54        m_name = name;
    5455        if ( !open() )
    5556        {
     
    6263string_view library::get_name() const
    6364{
    64     return string_view( m_name.c_str(), m_name.size() );
     65    return m_name;
    6566}
    6667
     
    7172        return true;
    7273    }
    73     NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loading..." );
     74    NV_LOG_NOTICE( "library \"", m_name, "\" : loading..." );
    7475
    75         std::string name = m_name;
     76        std::string name( m_name.data(), m_name.length() );
    7677        std::string ext( NV_LIB_EXT );
    7778
     
    8586    if ( m_handle == NULL )
    8687    {
    87                 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : failed to open!" );
     88                NV_LOG_NOTICE( "library \"", m_name, "\" : failed to open!" );
    8889                return false;
    8990    }
    90     NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loaded." );
    9191        return true;
    9292}
     
    9797    if ( !result )
    9898    {
    99                 NV_LOG_CRITICAL( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't find symbol \"", symbol, "\"" );
     99                NV_LOG_CRITICAL( "library \"", m_name, "\" : can't find symbol \"", symbol, "\"" );
    100100                NV_ABORT( "Library symbol load failed!" );
    101101    }
     
    117117    if ( ! NV_LIB_CLOSE( m_handle ) )
    118118    {
    119         NV_LOG_ERROR( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't close library!" );
     119        NV_LOG_ERROR( "library \"", m_name, "\" : can't close library!" );
    120120    }
    121121    m_handle = nullptr;
     
    130130}
    131131
    132 std::string library::get_error()
     132nv::string_view library::get_error()
    133133{
    134134#if NV_PLATFORM == NV_WINDOWS
    135135    // We do hate WinAPI for code like this, don't we?
    136     LPTSTR buffer = nullptr;
    137     FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    138         NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL );
    139     std::string msg( reinterpret_cast<char*>( buffer ) );
    140     LocalFree( buffer );
    141     return msg;
     136        static TCHAR buffer[256];
     137    FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
     138        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 256, NULL );
     139    return string_view( reinterpret_cast<char*>( buffer ) );
    142140#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
    143     return std::string( dlerror() );
     141    return nv::string_view( dlerror() );
    144142#else
    145     return std::string("");
     143    return nv::string_view();
    146144#endif
    147145}
  • trunk/src/gui/gui_gfx_renderer.cc

    r435 r437  
    235235        size_t size_before = er->buffer.data().size();
    236236
    237         std::vector< gui_quad >& qvec = er->buffer.lock();
     237        vector< gui_quad >& qvec = er->buffer.lock();
    238238
    239239        qvec.clear();
  • trunk/src/lua/lua_map_area.cc

    r431 r437  
    137137{
    138138        nv::map_area* ma = to_map_area( L, 1 );
    139         nv::string_view result( ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) );
    140         lua_pushlstring( L, result.data(), result.size() );
     139        nlua_pushstringview( L, ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) );
    141140        return 1;
    142141}
  • trunk/src/lua/lua_nova.cc

    r399 r437  
    817817        // TODO: check if nova is loaded
    818818        lua_pushcfunction( L, nova_register_storage );
    819         lua_pushlstring( L, name.data(), name.size() );
     819        nlua_pushstringview( L, name );
    820820        lua_call( L, 1, 1 );
    821821        lua_setglobal( L, constructor_name.data() );
  • trunk/src/lua/lua_raw.cc

    r435 r437  
    77#include "nv/lua/lua_raw.hh"
    88
    9 #include "nv/stl/string.hh"
    10 
    11 std::string nlua_typecontent( lua_State* L, int idx )
     9nv::string_view nlua_typecontent( lua_State* L, int idx )
    1210{
    1311        int type = lua_type( L, idx );
     
    1917        //case LUA_TLIGHTUSERDATA       : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) );
    2018        //case LUA_TNUMBER              : return std::to_string( lua_tonumber( L, idx ) );
    21         case LUA_TSTRING                : return lua_tostring( L, idx );
     19        // TODO: copy to buffer?
     20        case LUA_TSTRING                : return nlua_tostringview( L, idx );
    2221        case LUA_TTABLE             : return "TABLE";
    2322        case LUA_TFUNCTION              : return "FUNCTION";
     
    2625        default : break;
    2726        }
    28         char buffer_data[64];
     27        static char buffer_data[64];
    2928        nv::array_ref< char > buffer( buffer_data, 64 );
    3029        if ( type == LUA_TLIGHTUSERDATA || type == LUA_TUSERDATA )
    3130        {
    3231                size_t l = nv::uint64_to_buffer( buffer, nv::uint64( lua_touserdata( L, idx ) ) );
    33                 return std::string( buffer_data, l );
     32                return nv::string_view( buffer.data(), buffer.size() );
    3433        }
    3534        else if ( type == LUA_TNUMBER )
    3635        {
    3736                size_t l = nv::f64_to_buffer( buffer, lua_tonumber( L, idx ) );
    38                 return std::string( buffer_data, l );
     37                return nv::string_view( buffer.data(), buffer.size() );
    3938        }
    4039        return "UNKNOWN!";
  • trunk/src/lua/lua_state.cc

    r433 r437  
    134134        if ( status != 0 )
    135135        {
    136                 NV_LOG_ERROR( "Lua error : ", lua_tostring( m_state, -1 ) );
     136                NV_LOG_ERROR( "Lua error : ", nlua_tostringview( m_state, -1 ) );
    137137                lua_pop( m_state, 1 );
    138138        }
     
    402402        if (result)
    403403        {
    404                 NV_LOG_WARNING( "Failed to load string ", name, ": ", lua_tostring(m_state, -1));
     404                NV_LOG_WARNING( "Failed to load string ", name, ": ", nlua_tostringview(m_state, -1));
    405405                return false;
    406406        }
     
    414414        if (result)
    415415        {
    416                 NV_LOG_WARNING( "Failed to open file ", filename, ": ", lua_tostring( m_state, -1 ) );
     416                NV_LOG_WARNING( "Failed to open file ", filename, ": ", nlua_tostringview( m_state, -1 ) );
    417417                return false;
    418418        }
     
    425425        if (result)
    426426        {
    427                 NV_LOG_WARNING( "Failed to run script ", name, ": ", lua_tostring( m_state, -1 ) );
     427                NV_LOG_WARNING( "Failed to run script ", name, ": ", nlua_tostringview( m_state, -1 ) );
    428428                lua_pop( m_state, 1 );
    429429        }
     
    442442        for ( int i = 0; i < top; ++i )
    443443        {
    444                 NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1).c_str() );
     444                NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1) );
    445445        }
    446446}
     
    546546        if ( !object_index.is_valid() ) return;
    547547        lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() );
    548         lua_pushlstring( m_state, metaname.data(), metaname.size() );
     548        nlua_pushstringview( m_state, metaname );
    549549        lua_pushlightuserdata( m_state, pointer );
    550550        lua_rawset( m_state, -3 );
     
    572572        else
    573573                nlua_deepcopy( m_state, -2 );
    574         lua_pushlstring( m_state, id.data(), id.size() );
     574        nlua_pushstringview( m_state, id );
    575575        lua_pushvalue( m_state, -2 );
    576576        lua_rawset( m_state, -4 );
     
    590590                return;
    591591        }
    592         lua_pushlstring( m_state, id.data(), id.size() );
     592        nlua_pushstringview( m_state, id );
    593593        lua_pushnil( m_state );
    594594        lua_rawset( m_state, -3 );
Note: See TracChangeset for help on using the changeset viewer.