Changeset 503 for trunk/src/lua
- Timestamp:
- 06/28/16 21:09:19 (9 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_area.cc
r491 r503 459 459 } 460 460 461 void nv::lua::register_area( lua _State* L)462 { 463 int stack = lua_gettop( L);464 nlua_requiref( L, "area", luaopen_area, 1);465 lua_settop( L, stack );466 } 467 461 void nv::lua::register_area( lua::state* state ) 462 { 463 int stack = lua_gettop( state->get_raw() ); 464 nlua_requiref( state->get_raw(), "area", luaopen_area, 1); 465 lua_settop( state->get_raw(), stack ); 466 } 467 -
trunk/src/lua/lua_aux.cc
r490 r503 137 137 }; 138 138 139 void nv::lua::register_aux( lua _State* L)139 void nv::lua::register_aux( lua::state* state ) 140 140 { 141 nlua_register( L, "table", nluaaux_table_aux_f );142 nlua_register( L, "math", nluaaux_math_aux_f );141 nlua_register( state->get_raw(), "table", nluaaux_table_aux_f ); 142 nlua_register( state->get_raw(), "math", nluaaux_math_aux_f ); 143 143 } 144 144 -
trunk/src/lua/lua_map_area.cc
r490 r503 223 223 } 224 224 225 void nv::lua::register_map_area_interface( lua_State* L, int index ) 226 { 227 nlua_register( L, nlua_map_area_f, index ); 228 } 229 230 void nv::lua::register_map_area( lua_State* L ) 231 { 232 luaopen_map_area(L); 233 } 234 235 void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area ) 236 { 225 void nv::lua::register_map_area_interface( lua::state* state, int index ) 226 { 227 nlua_register( state->get_raw(), nlua_map_area_f, index ); 228 } 229 230 void nv::lua::register_map_area( lua::state* state ) 231 { 232 luaopen_map_area( state->get_raw() ); 233 } 234 235 void nv::lua::register_map_area_instance( lua::state* state, ref object_index, map_area* area ) 236 { 237 lua_State* L = state->get_raw(); 237 238 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() ); 238 239 lua_pushliteral( L, "__map_area_ptr" ); -
trunk/src/lua/lua_map_tile.cc
r490 r503 366 366 }; 367 367 368 void nv::lua::register_map_tile( lua _State * L)368 void nv::lua::register_map_tile( lua::state* state ) 369 369 { 370 370 // TODO: check if __gc is used! 371 lua_State* L = state->get_raw(); 371 372 luaL_newmetatable( L, NLUA_MAP_TILE_METATABLE ); 372 373 lua_pushvalue( L, -1 ); -
trunk/src/lua/lua_math.cc
r490 r503 359 359 } 360 360 361 void nv::lua::register_math( lua_State* L ) 361 template < typename T > 362 void nlua_rtti_vec_push( nv::lua::state* state, const nv::type_entry*, void* object ) 363 { 364 T* value = reinterpret_cast<T*>( object ); 365 push_vec<T>( state->get_raw(), *value ); 366 } 367 368 template < typename T > 369 bool nlua_rtti_vec_read( nv::lua::state* state, const nv::type_entry*, void* object, int index ) 370 { 371 T* value = reinterpret_cast<T*>( object ); 372 int type = lua_type( state->get_raw(), index ); 373 if ( type == LUA_TUSERDATA ) 374 { 375 T* from = to_pvec<T>( state->get_raw(), index ); 376 if ( !from ) return false; 377 *value = *from; 378 } 379 // else if ( type == LUA_TTABLE ) 380 // { 381 // 382 // } 383 else 384 return false; 385 int todo; int table_constructor; 386 return true; 387 } 388 389 void nv::lua::register_math( lua::state* state ) 362 390 { 363 391 for (size_t i = 0; i < 256; ++i ) nlua_swizzel_lookup[i] = 255; … … 379 407 nlua_swizzel_lookup[uchar8( 'v' )] = 0; 380 408 nlua_swizzel_lookup[uchar8( '3' )] = 3; 409 410 lua_State* L = state->get_raw(); 381 411 int stack = lua_gettop( L ); 382 412 … … 389 419 nlua_requiref(L, "vec4", luaopen_vec<nv::vec4>, 1); 390 420 lua_settop( L, stack ); 391 } 392 421 422 state->register_rtti_type< nv::ivec2 >( nlua_rtti_vec_push<nv::ivec2>, nlua_rtti_vec_read<nv::ivec2> ); 423 state->register_rtti_type< nv::ivec3 >( nlua_rtti_vec_push<nv::ivec3>, nlua_rtti_vec_read<nv::ivec3> ); 424 state->register_rtti_type< nv::ivec4 >( nlua_rtti_vec_push<nv::ivec4>, nlua_rtti_vec_read<nv::ivec4> ); 425 state->register_rtti_type< nv::vec2 > ( nlua_rtti_vec_push<nv::vec2>, nlua_rtti_vec_read<nv::vec2> ); 426 state->register_rtti_type< nv::vec3 > ( nlua_rtti_vec_push<nv::vec3>, nlua_rtti_vec_read<nv::vec3> ); 427 state->register_rtti_type< nv::vec4 > ( nlua_rtti_vec_push<nv::vec4>, nlua_rtti_vec_read<nv::vec4> ); 428 } 429 -
trunk/src/lua/lua_state.cc
r490 r503 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/lua/lua_nova.hh" 11 #include "nv/lua/lua_types.hh" 11 12 #include "nv/core/logging.hh" 12 13 #include "nv/stl/string.hh" … … 143 144 144 145 lua::table_guard::table_guard( lua::state* lstate, const path& p, bool global ) 145 : state_wrapper( lstate->get_raw(), false ), m_level(0)146 : state_wrapper( lstate->get_raw(), lstate->m_lua_types, false ), m_parent( lstate ), m_level(0) 146 147 { 147 148 m_global = false; … … 155 156 156 157 lua::table_guard::table_guard( const table_guard& parent, const path& p ) 157 : state_wrapper( parent.m_state, false), m_level(0)158 : state_wrapper( parent.m_state, parent.m_lua_types, false ), m_parent( parent.m_parent ), m_level(0) 158 159 { 159 160 m_global = false; … … 350 351 351 352 353 bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object ) 354 { 355 NV_ASSERT_ALWAYS( m_lua_types->get_type_database() == entry->type_db, "Type database mismatch between Lua and entry!" ); 356 lua_getfield( m_state, -1, element.data() ); 357 if ( lua_type( m_state, -1 ) != LUA_TTABLE ) 358 { 359 lua_pop( m_state, 1 ); 360 return false; 361 } 362 if ( !nv::lua::read_rtti_type( m_parent, entry, object, -1 ) ) 363 { 364 lua_pop( m_state, 1 ); 365 return false; 366 } 367 lua_pop( m_state, 1 ); 368 return true; 369 } 370 352 371 // state 353 372 354 lua::state::state( lua_State* state ) : state_wrapper( state, false ) 355 { 356 357 } 358 359 lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ) 373 lua::state::state( lua_State* state, type_database* types ) 374 : state_wrapper( state, new type_data( types ), false ) 375 { 376 377 } 378 379 lua::state::state( bool load_libs /*= false*/, type_database* types ) 380 : state_wrapper( nullptr, new type_data( types ), true ) 360 381 { 361 382 load_lua_library(); … … 575 596 } 576 597 598 void nv::lua::state::register_rtti_type( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r ) 599 { 600 m_lua_types->insert( tid, p, r ); 601 } 602 577 603 nv::lua::ref nv::lua::state::register_handle_component_impl( string_view id, bool empty ) 578 604 { … … 626 652 } 627 653 654 nv::lua::state::~state() 655 { 656 delete m_lua_types; 657 m_lua_types = nullptr; 658 } 659 660 template < typename T > 661 void nlua_rtti_signed_push( nv::lua::state* state, const type_entry*, void* object ) 662 { 663 T* value = reinterpret_cast<T*>( object ); 664 lua_pushinteger( state->get_raw(), lua_Integer( *value ) ); 665 } 666 667 template < typename T > 668 void nlua_rtti_unsigned_push( nv::lua::state* state, const type_entry*, void* object ) 669 { 670 T* value = reinterpret_cast<T*>( object ); 671 lua_pushinteger( state->get_raw(), lua_Unsigned( *value ) ); 672 } 673 674 template < typename T > 675 void nlua_rtti_floating_push( nv::lua::state* state, const type_entry*, void* object ) 676 { 677 T* value = reinterpret_cast< T* >( object ); 678 lua_pushnumber( state->get_raw(), lua_Number( *value ) ); 679 } 680 681 static void nlua_rtti_boolean_push( nv::lua::state* state, const type_entry*, void* object ) 682 { 683 bool* value = reinterpret_cast<bool*>( object ); 684 lua_pushboolean( state->get_raw(), *value ); 685 } 686 687 template < typename T > 688 bool nlua_rtti_signed_read( nv::lua::state* state, const type_entry*, void* object, int index ) 689 { 690 T* value = reinterpret_cast<T*>( object ); 691 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 692 { 693 *value = T( lua_tointeger( state->get_raw(), index ) ); 694 return true; 695 } 696 return false; 697 } 698 699 template < typename T > 700 bool nlua_rtti_unsigned_read( nv::lua::state* state, const type_entry*, void* object, int index ) 701 { 702 T* value = reinterpret_cast<T*>( object ); 703 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 704 { 705 *value = T( lua_tointeger( state->get_raw(), index ) ); 706 return true; 707 } 708 return false; 709 } 710 711 template < typename T > 712 bool nlua_rtti_floating_read( nv::lua::state* state, const type_entry*, void* object, int index ) 713 { 714 T* value = reinterpret_cast<T*>( object ); 715 if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER ) 716 { 717 *value = T( lua_tonumber( state->get_raw(), index ) ); 718 return true; 719 } 720 return false; 721 } 722 723 static bool nlua_rtti_boolean_read( nv::lua::state* state, const type_entry*, void* object, int index ) 724 { 725 bool* value = reinterpret_cast<bool*>( object ); 726 if ( lua_type( state->get_raw(), index ) == LUA_TBOOLEAN ) 727 { 728 *value = bool( lua_toboolean( state->get_raw(), index ) ); 729 return true; 730 } 731 return false; 732 } 733 734 735 void nv::lua::type_data::insert( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r ) 736 { 737 m_type_read.assign( tid, r ); 738 m_type_push.assign( tid, p ); 739 } 740 741 void nv::lua::type_data::register_standard_types() 742 { 743 insert<bool>( nlua_rtti_boolean_push, nlua_rtti_boolean_read ); 744 insert<nv::sint8> ( nlua_rtti_signed_push<nv::sint8>, nlua_rtti_signed_read<nv::sint8> ); 745 insert<nv::sint16>( nlua_rtti_signed_push<nv::sint16>, nlua_rtti_signed_read<nv::sint16> ); 746 insert<nv::sint32>( nlua_rtti_signed_push<nv::sint32>, nlua_rtti_signed_read<nv::sint32> ); 747 insert<nv::uint8> ( nlua_rtti_unsigned_push<nv::uint8>, nlua_rtti_unsigned_read<nv::uint8> ); 748 insert<nv::uint16>( nlua_rtti_unsigned_push<nv::uint16>, nlua_rtti_unsigned_read<nv::uint16> ); 749 insert<nv::uint32>( nlua_rtti_unsigned_push<nv::uint32>, nlua_rtti_unsigned_read<nv::uint32> ); 750 insert<nv::f32> ( nlua_rtti_floating_push<nv::f32>, nlua_rtti_floating_read<nv::f32> ); 751 insert<nv::f64> ( nlua_rtti_floating_push<nv::f64>, nlua_rtti_floating_read<nv::f64> ); 752 // insert<nv::sint64>( nlua_rtti_floating_push<nv::sint64>, nlua_rtti_floating_read<nv::sint64> ); 753 // insert<nv::uint64>( nlua_rtti_floating_push<nv::uint64>, nlua_rtti_floating_read<nv::uint64> ); 754 }
Note: See TracChangeset
for help on using the changeset viewer.