Changeset 358
- Timestamp:
- 04/29/15 14:53:06 (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/string_ref.hh
r357 r358 60 60 template< typename U, typename std::enable_if<std::is_same<U,const char*>::value>::type* = nullptr > 61 61 basic_string_ref( U str ) 62 : m_data( str ), m_length( TRAITS::length( str ) ) 63 { 64 static_assert( std::is_same<T, U>::value ); 65 } 62 : m_data( str ), m_length( TRAITS::length( str ) ) {} 66 63 67 64 basic_string_ref& operator=( const basic_string_ref &rhs ) -
trunk/nv/lua/lua_function.hh
r345 r358 9 9 10 10 #include <nv/core/common.hh> 11 #include <nv/core/string.hh>12 11 #include <nv/lua/lua_values.hh> 13 12 #include <nv/lua/lua_path.hh> -
trunk/nv/lua/lua_nova.hh
r319 r358 13 13 namespace lua 14 14 { 15 void register_storage( state* a_state, const string& name, const string&constructor_name );15 void register_storage( state* a_state, string_ref name, string_ref constructor_name ); 16 16 void register_nova( state* a_state ); 17 17 } -
trunk/nv/lua/lua_state.hh
r345 r358 15 15 #include <nv/core/flags.hh> 16 16 #include <nv/core/handle.hh> 17 #include <nv/core/string_ref.hh> 17 18 #include <istream> 18 19 #include <map> -
trunk/nv/lua/lua_values.hh
r349 r358 11 11 #include <nv/core/type_traits.hh> 12 12 #include <nv/core/string.hh> 13 #include <nv/core/string_ref.hh> 13 14 14 15 struct lua_State; … … 74 75 void push_bool ( lua_State *L, bool v ); 75 76 void push_string ( lua_State *L, const std::string& s ); 77 void push_string_ref ( lua_State *L, string_ref s ); 76 78 void push_cstring ( lua_State *L, const char* s ); 77 79 void push_pointer ( lua_State *L, void* p ); … … 84 86 std::string to_string ( lua_State *L, int index ); 85 87 const char* to_cstring ( lua_State *L, int index ); 88 string_ref to_string_ref ( lua_State *L, int index ); 86 89 void* to_pointer ( lua_State *L, int index ); 87 90 void* to_ref_object ( lua_State *L, int index ); … … 93 96 std::string to_string ( lua_State *L, int index, const std::string& def ); 94 97 const char* to_cstring ( lua_State *L, int index, const char* def ); 98 string_ref to_string_ref ( lua_State *L, int index, string_ref def ); 95 99 void* to_pointer ( lua_State *L, int index, void* def ); 96 100 void* to_ref_object ( lua_State *L, int index, void* def ); … … 156 160 157 161 template <> 162 struct pass_traits < string_ref > 163 { 164 static void push( lua_State *L, string_ref s ) { detail::push_string_ref( L, s ); } 165 static string_ref to( lua_State *L, int index ) { return detail::to_string_ref( L, index ); } 166 static string_ref to( lua_State *L, int index, string_ref def ) { return detail::to_string_ref( L, index, def ); } 167 }; 168 169 template <> 158 170 struct pass_traits<ref> 159 171 { -
trunk/src/engine/resource_system.cc
r323 r358 14 14 std::string constructor_name( get_resource_name() ); 15 15 constructor_name = "register_"+constructor_name; 16 lua::register_storage( m_lua, get_storage_name(), constructor_name.c_str() ); 16 int correct = 0; 17 lua::register_storage( m_lua, get_storage_name(), constructor_name ); 17 18 } 18 19 -
trunk/src/lua/lua_nova.cc
r323 r358 83 83 lua_pushvalue( L, itype ); 84 84 lua_pushvalue( L, iid ); 85 lua_push string( L, "." );85 lua_pushliteral( L, "." ); 86 86 lua_pushvalue( L, ifield ); 87 87 lua_concat( L, 3 ); … … 292 292 { 293 293 // storage.__counter++ 294 lua_push string( L, "__counter" );294 lua_pushliteral( L, "__counter" ); 295 295 lua_pushvalue( L, -1 ); 296 296 lua_rawget( L, 1 ); … … 303 303 304 304 // element.nid = __counter 305 lua_push string( L, "nid" );305 lua_pushliteral( L, "nid" ); 306 306 lua_pushinteger( L, count ); 307 307 lua_rawset( L, 2 ); … … 322 322 323 323 // element.id = element.id 324 lua_push string( L, "id" );324 lua_pushliteral( L, "id" ); 325 325 lua_rawget( L, 2 ); 326 326 if ( lua_isnil( L, -1 ) ) … … 413 413 414 414 lua_pushvalue( L, 1 ); 415 lua_push string( L, "." );415 lua_pushliteral( L, "." ); 416 416 lua_pushvalue( L, 2 ); 417 417 lua_concat( L, 3 ); // new ident index 5 … … 449 449 450 450 lua_pushvalue( L, 1 ); 451 lua_push string( L, "." );451 lua_pushliteral( L, "." ); 452 452 lua_pushvalue( L, 2 ); 453 453 lua_concat( L, 3 ); // new ident index 6 … … 579 579 if ( lua_type( L, 1 ) == LUA_TSTRING ) 580 580 { 581 // TODO: Optimzie 581 582 lua_getglobal( L, lua_tostring( L, 1 ) ); 582 583 lua_replace( L, 1 ); … … 809 810 } 810 811 811 void nv::lua::register_storage( state* a_state, const string& name, const string&constructor_name )812 void nv::lua::register_storage( state* a_state, string_ref name, string_ref constructor_name ) 812 813 { 813 814 // TODO: error checking … … 816 817 // TODO: check if nova is loaded 817 818 lua_pushcfunction( L, nova_register_storage ); 818 lua_push string( L, name.c_str() );819 lua_pushlstring( L, name.data(), name.size() ); 819 820 lua_call( L, 1, 1 ); 820 lua_setglobal( L, constructor_name. c_str() );821 lua_setglobal( L, constructor_name.data() ); 821 822 lua_settop( L, stack ); 822 823 } -
trunk/src/lua/lua_values.cc
r319 r358 75 75 } 76 76 77 void nv::lua::detail::push_string_ref( lua_State *L, string_ref s ) 78 { 79 lua_pushlstring( L, s.data(), s.size() ); 80 } 81 77 82 void nv::lua::detail::push_pointer ( lua_State *L, void* p ) 78 83 { … … 108 113 std::string nv::lua::detail::to_string ( lua_State *L, int index ) 109 114 { 110 return lua_tostring( L, index ); 115 size_t length = 0; 116 const char* result = lua_tolstring( L, index, &length ); 117 return std::string( result, length ); 111 118 } 112 119 113 120 const char* nv::lua::detail::to_cstring ( lua_State *L, int index ) 114 121 { 115 return lua_tostring( L, index ); 122 return lua_tolstring( L, index, nullptr ); 123 } 124 125 nv::string_ref nv::lua::detail::to_string_ref( lua_State *L, int index ) 126 { 127 size_t length = 0; 128 const char* result = lua_tolstring( L, index, &length ); 129 return string_ref( result, length ); 116 130 } 117 131
Note: See TracChangeset
for help on using the changeset viewer.