Changeset 540 for trunk/src/lua
- Timestamp:
- 01/25/17 20:20:45 (8 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_proxy.cc
r539 r540 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/lua/lua_state.hh" 11 #include "nv/lua/lua_types.hh" 11 12 12 13 using namespace nv; … … 58 59 } 59 60 61 bool nv::lua::stack_proxy::is_valid() const 62 { 63 return !( lua_isnil( *m_state, m_index ) ); 64 } 65 66 bool nv::lua::stack_proxy::read( const type_entry* entry, void* object ) const 67 { 68 NV_ASSERT_ALWAYS( m_state->get_type_data()->get_type_database() == entry->type_db, "Type database mismatch between Lua and entry!" ); 69 if ( lua_type( *m_state, m_index ) != LUA_TTABLE ) return false; 70 return nv::lua::read_rtti_type( m_state, entry, object, m_index ); 71 } 72 60 73 bool nv::lua::stack_proxy::is_table() const 61 74 { -
trunk/src/lua/lua_state.cc
r539 r540 153 153 // TODO : error handling 154 154 } 155 m_index = -1; 155 156 } 156 157 … … 165 166 // TODO : error handling 166 167 } 168 m_index = -1; 167 169 } 168 170 169 171 lua::table_guard::~table_guard() 170 172 { 171 lua_settop( m_state, m_level );172 } 173 174 nv::uint32 lua::table_guard::get_size() 175 { 176 return nlua_rawlen( m_state, -1 ); 177 } 178 179 bool lua::table_guard::has_field( string_view element ) 180 { 181 lua_getfield( m_state, -1, element.data() );182 bool result = !( lua_isnil( m_state, -1 ) ); 183 lua_pop( m_state, 1);184 return result;173 if ( m_index == -1 ) 174 lua_settop( m_state, m_level ); 175 } 176 177 nv::uint32 lua::table_guard::size() 178 { 179 return nlua_rawlen( m_state, m_index ); 180 } 181 182 nv::lua::table_guard::table_guard( stack_proxy& proxy ) 183 : state_wrapper( *proxy.m_state, proxy.m_state->m_lua_types, false ), m_parent( proxy.m_state ), m_level( 0 ) 184 { 185 m_level = lua_gettop( m_state ); 186 m_index = proxy.m_index; 185 187 } 186 188 187 189 const nv::lua::temporary_proxy nv::lua::table_guard::operator[]( const string_view& key ) const 188 190 { 189 lua_getfield( m_state, -1, key.data() );191 lua_getfield( m_state, m_index, key.data() ); 190 192 return temporary_proxy( m_parent ); 191 193 } … … 193 195 const nv::lua::temporary_proxy nv::lua::table_guard::operator[]( sint32 key ) const 194 196 { 195 lua_rawgeti( m_state, -1, key );197 lua_rawgeti( m_state, m_index, key ); 196 198 return temporary_proxy( m_parent ); 197 }198 199 bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object )200 {201 NV_ASSERT_ALWAYS( m_lua_types->get_type_database() == entry->type_db, "Type database mismatch between Lua and entry!" );202 lua_getfield( m_state, -1, element.data() );203 if ( lua_type( m_state, -1 ) != LUA_TTABLE )204 {205 lua_pop( m_state, 1 );206 return false;207 }208 if ( !nv::lua::read_rtti_type( m_parent, entry, object, -1 ) )209 {210 lua_pop( m_state, 1 );211 return false;212 }213 lua_pop( m_state, 1 );214 return true;215 199 } 216 200 … … 590 574 } 591 575 576 template < typename T > 577 bool nlua_rtti_string_read( nv::lua::state* state, const type_entry*, void* object, int index ) 578 { 579 T* value = reinterpret_cast<T*>( object ); 580 if ( lua_type( state->get_raw(), index ) == LUA_TSTRING ) 581 { 582 *value = T( nlua_tostringview( state->get_raw(), index ) ); 583 return true; 584 } 585 return false; 586 } 587 592 588 593 589 void nv::lua::type_data::insert( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r ) … … 608 604 insert<nv::f32> ( nlua_rtti_floating_push<nv::f32>, nlua_rtti_floating_read<nv::f32> ); 609 605 insert<nv::f64> ( nlua_rtti_floating_push<nv::f64>, nlua_rtti_floating_read<nv::f64> ); 610 // insert<nv::sint64>( nlua_rtti_floating_push<nv::sint64>, nlua_rtti_floating_read<nv::sint64> ); 606 insert<nv::shash32> ( nullptr, nlua_rtti_string_read<nv::shash32> ); 607 insert<nv::shash64> ( nullptr, nlua_rtti_string_read<nv::shash64> ); 608 insert<nv::string32> ( nullptr, nlua_rtti_string_read<nv::string32> ); 609 insert<nv::string64> ( nullptr, nlua_rtti_string_read<nv::string64> ); 610 insert<nv::string128>( nullptr, nlua_rtti_string_read<nv::string128> ); 611 // insert<nv::sint64>( nlua_rtti_floating_push<nv::sint64>, nlua_rtti_floating_read<nv::sint64> ); 611 612 // insert<nv::uint64>( nlua_rtti_floating_push<nv::uint64>, nlua_rtti_floating_read<nv::uint64> ); 612 613 }
Note: See TracChangeset
for help on using the changeset viewer.