Changeset 440 for trunk/src/lua
- Timestamp:
- 07/23/15 21:16:01 (10 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_function.cc
r433 r440 21 21 { 22 22 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() ); 24 24 } 25 25 … … 27 27 { 28 28 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() ); 30 30 } 31 31 m_ref = luaL_ref( L, LUA_REGISTRYINDEX ); … … 64 64 if ( status != 0 ) 65 65 { 66 st d::string error = lua_tostring( L, -1);66 string128 error( nlua_tostringview( L, -1 ) ); 67 67 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 ); 69 69 } 70 70 } -
trunk/src/lua/lua_map_tile.cc
r433 r440 16 16 #include "nv/lua/lua_values.hh" 17 17 #include "nv/lua/lua_raw.hh" 18 19 // TODO: REMOVE 20 #include <string> 18 21 19 22 static const char* NLUA_MAP_TILE_METATABLE = "map_tile"; -
trunk/src/lua/lua_path.cc
r435 r440 74 74 } 75 75 76 st d::stringnv::lua::path::to_string() const76 string128 nv::lua::path::to_string() const 77 77 { 78 char buffer[64]; 79 char* start = buffer; 80 char* current = buffer; 78 string128 buffer; 81 79 bool dot = false; 82 bool oos = false;83 80 for ( const element& e : m_elements ) 84 81 { 85 if ( current - start > 48 ) { oos = true; break; } 86 if ( dot ) *current++ = '.'; 82 if ( dot ) buffer.append( "." ); 87 83 if ( e.length == 0 ) 88 84 { 89 *current++ = '['; 90 current += uint32_to_buffer( array_ref< char >( current, current - start ), e.value ); 91 *current++ = ']'; 85 buffer.append( "["_ls + e.value + "]"_ls ); 92 86 dot = false; 93 87 } 94 88 else 95 89 { 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 ); 99 91 dot = true; 100 92 } 101 93 } 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; 110 95 } -
trunk/src/lua/lua_state.cc
r437 r440 116 116 if ( !p.resolve( m_state, global ) ) 117 117 { 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() ); 119 119 return false; 120 120 } … … 123 123 { 124 124 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() ); 126 126 return false; 127 127 } … … 212 212 lua_pop( m_state, 1 ); 213 213 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 else226 {227 l = defval.size();228 str = defval.data();229 }230 std::string result( str, l );231 lua_pop( m_state, 1 );232 return result;233 214 } 234 215 … … 250 231 lua_pop( m_state, 1 ); 251 232 return result; 233 } 234 235 string128 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; 252 252 } 253 253 -
trunk/src/lua/lua_values.cc
r399 r440 65 65 } 66 66 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 72 67 void nv::lua::detail::push_cstring ( lua_State *L, const char* s ) 73 68 { … … 109 104 { 110 105 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 );118 106 } 119 107 … … 171 159 } 172 160 173 std::string nv::lua::detail::to_string ( lua_State *L, int index, const std::string&def )161 nv::string_view nv::lua::detail::to_string_view( lua_State *L, int index, string_view def ) 174 162 { 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 ); 176 164 } 177 165
Note: See TracChangeset
for help on using the changeset viewer.