Changeset 360 for trunk/src/lua
- Timestamp:
- 05/04/15 16:30:44 (10 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_map_area.cc
r319 r360 57 57 if ( lua_istable( L , index ) ) 58 58 { 59 lua_push string( L, "__map_area_ptr" );59 lua_pushliteral( L, "__map_area_ptr" ); 60 60 lua_rawget( L, index ); 61 61 if ( lua_isuserdata( L, -1 ) ) … … 96 96 static int nlua_map_area_tostring( lua_State* L ) 97 97 { 98 lua_push string( L, "map_area" );98 lua_pushliteral ( L, "map_area" ); 99 99 return 1; 100 100 } … … 236 236 { 237 237 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() ); 238 lua_push string( L, "__map_area_ptr" );238 lua_pushliteral( L, "__map_area_ptr" ); 239 239 lua_pushlightuserdata( L, (map_area*)area ); 240 240 lua_rawset( L, -3 ); -
trunk/src/lua/lua_path.cc
r359 r360 18 18 size_t point = spath.find( '.' ); 19 19 20 while ( point != st d::string::npos )20 while ( point != string_ref::npos ) 21 21 { 22 22 m_elements[m_count].str = spath.data(); -
trunk/src/lua/lua_state.cc
r341 r360 80 80 } 81 81 82 void lua::state_wrapper::register_native_function( lfunction f, const char*name )82 void lua::state_wrapper::register_native_function( lfunction f, string_ref name ) 83 83 { 84 84 if ( m_global ) push_global_table(); 85 85 lua_pushcfunction( m_state, f ); 86 lua_setfield( m_state, -2, name );86 lua_setfield( m_state, -2, name.data() ); 87 87 if ( m_global ) pop_global_table(); 88 88 } … … 129 129 if ( status != 0 ) 130 130 { 131 std::string error = lua_tostring( m_state, -1);131 NV_LOG( LOG_ERROR, "Lua error : " << lua_tostring( m_state, -1 ) ); 132 132 lua_pop( m_state, 1 ); 133 NV_LOG( LOG_ERROR, "Lua error : " << error )134 133 } 135 134 return status; … … 172 171 } 173 172 174 bool lua::table_guard::has_field( const string&element )175 { 176 lua_getfield( m_state, -1, element. c_str() );173 bool lua::table_guard::has_field( string_ref element ) 174 { 175 lua_getfield( m_state, -1, element.data() ); 177 176 bool result = !( lua_isnil( m_state, -1 ) ); 178 177 lua_pop( m_state, 1 ); … … 180 179 } 181 180 182 string lua::table_guard::get_string( const string& element, const string& defval /*= ""*/ )183 { 184 lua_getfield( m_state, -1, element. c_str() );185 string result( ( lua_type( m_state, -1 ) == LUA_TSTRING ) ? lua_tostring( m_state, -1 ) : defval );186 lua_pop( m_state, 1 ); 187 return result; 188 } 189 190 char lua::table_guard::get_char( const string&element, char defval /*= "" */ )191 { 192 lua_getfield( m_state, -1, element. c_str() );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; 187 } 188 189 char lua::table_guard::get_char( string_ref element, char defval /*= "" */ ) 190 { 191 lua_getfield( m_state, -1, element.data() ); 193 192 char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && lua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval; 194 193 lua_pop( m_state, 1 ); … … 196 195 } 197 196 198 int lua::table_guard::get_integer( const string&element, int defval /*= "" */ )199 { 200 lua_getfield( m_state, -1, element. c_str() );197 int lua::table_guard::get_integer( string_ref element, int defval /*= "" */ ) 198 { 199 lua_getfield( m_state, -1, element.data() ); 201 200 lua_Integer result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tointeger( m_state, -1 ) : defval; 202 201 lua_pop( m_state, 1 ); … … 204 203 } 205 204 206 unsigned lua::table_guard::get_unsigned( const string&element, unsigned defval /*= "" */ )207 { 208 lua_getfield( m_state, -1, element. c_str() );205 unsigned lua::table_guard::get_unsigned( string_ref element, unsigned defval /*= "" */ ) 206 { 207 lua_getfield( m_state, -1, element.data() ); 209 208 unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tounsigned( m_state, -1 ) : defval; 210 209 lua_pop( m_state, 1 ); … … 212 211 } 213 212 214 double lua::table_guard::get_double( const string&element, double defval /*= "" */ )215 { 216 lua_getfield( m_state, -1, element. c_str() );213 double lua::table_guard::get_double( string_ref element, double defval /*= "" */ ) 214 { 215 lua_getfield( m_state, -1, element.data() ); 217 216 double result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tonumber( m_state, -1 ) : defval; 218 217 lua_pop( m_state, 1 ); … … 221 220 222 221 223 float nv::lua::table_guard::get_float( const std::string&element, float defval /*= 0.0 */ )224 { 225 lua_getfield( m_state, -1, element. c_str() );222 float nv::lua::table_guard::get_float( string_ref element, float defval /*= 0.0 */ ) 223 { 224 lua_getfield( m_state, -1, element.data() ); 226 225 float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? (float)lua_tonumber( m_state, -1 ) : defval; 227 226 lua_pop( m_state, 1 ); … … 229 228 } 230 229 231 bool lua::table_guard::get_boolean( const string&element, bool defval /*= "" */ )232 { 233 lua_getfield( m_state, -1, element. c_str() );230 bool lua::table_guard::get_boolean( string_ref element, bool defval /*= "" */ ) 231 { 232 lua_getfield( m_state, -1, element.data() ); 234 233 bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN ? lua_toboolean( m_state, -1 ) != 0 : defval; 235 234 lua_pop( m_state, 1 ); … … 237 236 } 238 237 239 bool nv::lua::table_guard::is_table( const std::string&element )240 { 241 lua_getfield( m_state, -1, element. c_str() );238 bool nv::lua::table_guard::is_table( string_ref element ) 239 { 240 lua_getfield( m_state, -1, element.data() ); 242 241 bool result = lua_type( m_state, -1 ) == LUA_TTABLE; 243 242 lua_pop( m_state, 1 ); … … 245 244 } 246 245 247 bool nv::lua::table_guard::is_number( const std::string&element )248 { 249 lua_getfield( m_state, -1, element. c_str() );246 bool nv::lua::table_guard::is_number( string_ref element ) 247 { 248 lua_getfield( m_state, -1, element.data() ); 250 249 bool result = lua_type( m_state, -1 ) == LUA_TNUMBER; 251 250 lua_pop( m_state, 1 ); … … 253 252 } 254 253 255 bool nv::lua::table_guard::is_boolean( const std::string&element )256 { 257 lua_getfield( m_state, -1, element. c_str() );254 bool nv::lua::table_guard::is_boolean( string_ref element ) 255 { 256 lua_getfield( m_state, -1, element.data() ); 258 257 bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN; 259 258 lua_pop( m_state, 1 ); … … 261 260 } 262 261 263 bool nv::lua::table_guard::is_string( const std::string&element )264 { 265 lua_getfield( m_state, -1, element. c_str() );262 bool nv::lua::table_guard::is_string( string_ref element ) 263 { 264 lua_getfield( m_state, -1, element.data() ); 266 265 bool result = lua_type( m_state, -1 ) == LUA_TSTRING; 267 266 lua_pop( m_state, 1 ); … … 321 320 } 322 321 323 int lua::state::load_string( const std::string& code, const std::string&name )322 int lua::state::load_string( string_ref code, string_ref name ) 324 323 { 325 324 NV_LOG( nv::LOG_TRACE, "Loading Lua string '" << name << "'"); 326 return luaL_loadbuffer( m_state, code. c_str(), code.length(), name.c_str() );327 } 328 329 int lua::state::load_stream( std::istream& stream, const std::string&name )325 return luaL_loadbuffer( m_state, code.data(), code.length(), name.data() ); 326 } 327 328 int lua::state::load_stream( std::istream& stream, string_ref name ) 330 329 { 331 330 NV_LOG( nv::LOG_NOTICE, "Loading Lua stream '" << name << "'"); … … 335 334 } 336 335 337 int lua::state::load_file( const std::string&filename )336 int lua::state::load_file( string_ref filename ) 338 337 { 339 338 NV_LOG( nv::LOG_NOTICE, "Loading Lua file '" << filename << "'"); 340 return luaL_loadfile( m_state, filename. c_str() );341 } 342 343 bool lua::state::do_string( const std::string& code, const std::string&name, int rvalues )339 return luaL_loadfile( m_state, filename.data() ); 340 } 341 342 bool lua::state::do_string( string_ref code, string_ref name, int rvalues ) 344 343 { 345 344 lua::stack_guard( this ); … … 353 352 } 354 353 355 bool lua::state::do_stream( std::istream& stream, const std::string&name )354 bool lua::state::do_stream( std::istream& stream, string_ref name ) 356 355 { 357 356 lua::stack_guard( this ); … … 365 364 } 366 365 367 bool lua::state::do_file( const std::string&filename )366 bool lua::state::do_file( string_ref filename ) 368 367 { 369 368 lua::stack_guard( this ); … … 377 376 } 378 377 379 int lua::state::do_current( const std::string&name, int rvalues )378 int lua::state::do_current( string_ref name, int rvalues ) 380 379 { 381 380 int result = lua_pcall(m_state, 0, rvalues, 0); … … 408 407 } 409 408 410 lua::ref lua::state::register_object( void* o, const char*lua_name )409 lua::ref lua::state::register_object( void* o, string_ref lua_name ) 411 410 { 412 411 if ( o == nullptr ) return lua::ref( lua::ref::none ); 413 412 stack_guard guard( this ); 414 lua_getglobal( m_state, lua_name );413 lua_getglobal( m_state, lua_name.data() ); 415 414 if ( lua_isnil( m_state, -1 ) ) 416 415 { 417 NV_THROW( runtime_error, std::string( lua_name) + " type not registered!" );416 NV_THROW( runtime_error, lua_name.to_string() + " type not registered!" ); 418 417 } 419 418 deep_pointer_copy( -1, o ); … … 421 420 } 422 421 423 lua::ref lua::state::register_proto( const char* id, const char*storage )422 lua::ref lua::state::register_proto( string_ref id, string_ref storage ) 424 423 { 425 424 stack_guard guard( this ); 426 lua_getglobal( m_state, storage );425 lua_getglobal( m_state, storage.data() ); 427 426 if ( lua_isnil( m_state, -1 ) ) 428 427 { 429 NV_THROW( runtime_error, st d::string( storage) + " storage not registered!" );430 } 431 lua_getfield( m_state, -1, id );428 NV_THROW( runtime_error, storage.to_string() + " storage not registered!" ); 429 } 430 lua_getfield( m_state, -1, id.data() ); 432 431 if ( lua_isnil( m_state, -1 ) ) 433 432 { 434 NV_THROW( runtime_error, std::string( id ) + " not found in " + std::string( storage) + " storage!" );433 NV_THROW( runtime_error, id.to_string() + " not found in " + storage.to_string() + " storage!" ); 435 434 } 436 435 return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) ); 437 436 } 438 437 439 void lua::state::register_native_object_method( const char* lua_name, const char*name, lfunction f )438 void lua::state::register_native_object_method( string_ref lua_name, string_ref name, lfunction f ) 440 439 { 441 440 stack_guard guard( this ); 442 lua_getglobal( m_state, lua_name );441 lua_getglobal( m_state, lua_name.data() ); 443 442 if ( lua_isnil( m_state, -1 ) ) 444 443 { 445 NV_THROW( runtime_error, std::string( lua_name) + " type not registered!" );444 NV_THROW( runtime_error, lua_name.to_string() + " type not registered!" ); 446 445 } 447 446 lua_pushcfunction( m_state, f ); 448 lua_setfield( m_state, -2, name );447 lua_setfield( m_state, -2, name.data() ); 449 448 } 450 449 … … 454 453 stack_guard guard( this ); 455 454 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() ); 456 lua_push string( m_state, "__ptr" );455 lua_pushliteral( m_state, "__ptr" ); 457 456 lua_pushboolean( m_state, false ); 458 457 lua_rawset( m_state, -3 ); … … 499 498 } 500 499 501 void nv::lua::state::store_metadata( ref object_index, const std::string&metaname, void* pointer )500 void nv::lua::state::store_metadata( ref object_index, string_ref metaname, void* pointer ) 502 501 { 503 502 if ( !object_index.is_valid() ) return; 504 503 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() ); 505 lua_push string( m_state, metaname.c_str() );504 lua_pushlstring( m_state, metaname.data(), metaname.size() ); 506 505 lua_pushlightuserdata( m_state, pointer ); 507 506 lua_rawset( m_state, -3 ); … … 509 508 } 510 509 511 void nv::lua::state::register_enum( const char*name, int value )510 void nv::lua::state::register_enum( string_ref name, int value ) 512 511 { 513 512 lua_pushinteger( m_state, value ); 514 lua_setglobal( m_state, name );515 } 516 517 nv::lua::ref nv::lua::state::register_handle_component_impl( const std::string&id, bool empty )513 lua_setglobal( m_state, name.data() ); 514 } 515 516 nv::lua::ref nv::lua::state::register_handle_component_impl( string_ref id, bool empty ) 518 517 { 519 518 int args = empty ? 1 : 2; … … 529 528 else 530 529 nlua_deepcopy( m_state, -2 ); 531 lua_push string( m_state, id.c_str() );530 lua_pushlstring( m_state, id.data(), id.size() ); 532 531 lua_pushvalue( m_state, -2 ); 533 532 lua_rawset( m_state, -4 ); … … 538 537 } 539 538 540 void nv::lua::state::unregister_handle_component_impl( const std::string&id )539 void nv::lua::state::unregister_handle_component_impl( string_ref id ) 541 540 { 542 541 NV_LUA_STACK_ASSERT( m_state, -1 ); … … 547 546 return; 548 547 } 549 lua_push string( m_state, id.c_str() );548 lua_pushlstring( m_state, id.data(), id.size() ); 550 549 lua_pushnil( m_state ); 551 550 lua_rawset( m_state, -3 ); … … 553 552 } 554 553 555 void nv::lua::state::register_singleton( const char*name, void* o )554 void nv::lua::state::register_singleton( string_ref name, void* o ) 556 555 { 557 556 if ( o == nullptr ) return; 558 557 stack_guard guard( this ); 559 lua_getglobal( m_state, name );558 lua_getglobal( m_state, name.data() ); 560 559 if ( lua_isnil( m_state, -1 ) ) 561 560 { 562 NV_THROW( runtime_error, std::string( name) + " type not registered!" );561 NV_THROW( runtime_error, name.to_string() + " type not registered!" ); 563 562 } 564 563 deep_pointer_copy( -1, o ); 565 lua_setglobal( m_state, name );566 } 567 564 lua_setglobal( m_state, name.data() ); 565 } 566 -
trunk/src/lua/lua_values.cc
r358 r360 191 191 if ( lua_istable( L , index ) ) 192 192 { 193 lua_push string( L, "__ptr" );193 lua_pushliteral( L, "__ptr" ); 194 194 lua_rawget( L, index ); 195 195 if ( lua_isuserdata( L, -1 ) )
Note: See TracChangeset
for help on using the changeset viewer.