Changeset 341 for trunk/src/lua
- Timestamp:
- 09/25/14 00:16:14 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_state.cc
r334 r341 515 515 } 516 516 517 nv::lua::ref nv::lua::state::register_handle_component_impl( const std::string& id, bool empty ) 518 { 519 int args = empty ? 1 : 2; 520 NV_LUA_STACK_ASSERT( m_state, -args ); 521 522 if ( lua_isnil( m_state, -1 ) || (!empty && lua_isnil( m_state, -2 )) ) 523 { 524 lua_pop( m_state, args ); 525 return ref(); 526 } 527 if (empty) 528 lua_createtable( m_state, 0, 0 ); 529 else 530 nlua_deepcopy( m_state, -2 ); 531 lua_pushstring( m_state, id.c_str() ); 532 lua_pushvalue( m_state, -2 ); 533 lua_rawset( m_state, -4 ); 534 lua_replace( m_state, -2 ); 535 ref result = lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) ); 536 if (!empty) lua_pop( m_state, 1 ); 537 return result; 538 } 539 540 void nv::lua::state::unregister_handle_component_impl( const std::string& id ) 541 { 542 NV_LUA_STACK_ASSERT( m_state, -1 ); 543 544 if ( lua_isnil( m_state, -1 ) ) 545 { 546 lua_pop( m_state, 1 ); 547 return; 548 } 549 lua_pushstring( m_state, id.c_str() ); 550 lua_pushnil( m_state ); 551 lua_rawset( m_state, -3 ); 552 lua_pop( m_state, 1 ); 553 } 554 555 void nv::lua::state::register_singleton( const char* name, void* o ) 556 { 557 if ( o == nullptr ) return; 558 stack_guard guard( this ); 559 lua_getglobal( m_state, name ); 560 if ( lua_isnil( m_state, -1 ) ) 561 { 562 NV_THROW( runtime_error, std::string( name ) + " type not registered!" ); 563 } 564 deep_pointer_copy( -1, o ); 565 lua_setglobal( m_state, name ); 566 } 567
Note: See TracChangeset
for help on using the changeset viewer.