Changeset 265
- Timestamp:
- 06/19/14 02:22:56 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/lua/lua_map_area.hh
r263 r265 22 22 void register_map_area( lua_State* L ); 23 23 void register_map_area_interface( lua_State* L, int index ); 24 void register_map_area_instance( lua_State* L, intobject_index, map_area* area );24 void register_map_area_instance( lua_State* L, ref object_index, map_area* area ); 25 25 26 26 namespace detail -
trunk/nv/lua/lua_object.hh
r262 r265 27 27 }; 28 28 29 void push_object ( lua_State *L, object* o );30 void* to_object ( lua_State *L, int index );31 void* to_object ( lua_State *L, int index, void* def );32 33 29 } 34 30 … … 36 32 struct pass_traits<object*> 37 33 { 38 static void push( lua_State *L, object* o ) { detail::push_object( L, o ); } 34 static void push( lua_State *L, object* o ) 35 { 36 if ( o ) 37 detail::push_ref_object( L, lua::ref(o->get_lua_index()) ); 38 else 39 detail::push_nil( L ); 40 } 39 41 static object* to( lua_State *L, int index ) { return static_cast< object* >( detail::to_ref_object( L, index ) ); } 40 42 static object* to( lua_State *L, int index, object* def ) { return static_cast< object* >( detail::to_ref_object( L, index, def ) ); } -
trunk/nv/lua/lua_state.hh
r262 r265 26 26 namespace lua 27 27 { 28 const int ref_none = -2; 29 const int ref_nil = -1; 28 30 29 const int ret_multi = -1; 31 32 typedef int reference;33 30 34 31 class state_wrapper … … 196 193 void log_stack(); 197 194 lua_State* get_raw(); 198 ref erenceregister_object( void* o, const char* lua_name );199 ref erenceregister_proto( const char* id, const char* storage );200 void store_metadata( ref erenceobject_index, const std::string& metaname, void* pointer );201 void unregister_object( ref erenceobject_index );195 ref register_object( void* o, const char* lua_name ); 196 ref register_proto( const char* id, const char* storage ); 197 void store_metadata( ref object_index, const std::string& metaname, void* pointer ); 198 void unregister_object( ref object_index ); 202 199 203 200 void register_enum( const char* name, int value ); -
trunk/nv/lua/lua_values.hh
r262 r265 18 18 namespace lua 19 19 { 20 class ref 21 { 22 public: 23 static const int none = -2; 24 static const int nil = -1; 25 26 ref() : m_value( nil ) {} 27 explicit ref( int lua_ref ) : m_value( lua_ref ) {} 28 bool is_valid() const { return m_value >= 0; } 29 int get() const { return m_value; } 30 protected: 31 int m_value; 32 }; 33 20 34 typedef ptrdiff_t linteger; 21 35 typedef unsigned long lunsigned; … … 54 68 int upvalue_index( int i ); 55 69 56 void push_unsigned( lua_State *L, lunsigned v ); 57 void push_integer ( lua_State *L, linteger v ); 58 void push_number ( lua_State *L, lnumber v ); 59 void push_bool ( lua_State *L, bool v ); 60 void push_string ( lua_State *L, const std::string& s ); 61 void push_cstring ( lua_State *L, const char* s ); 62 void push_pointer ( lua_State *L, void* p ); 70 void push_nil ( lua_State *L ); 71 void push_unsigned ( lua_State *L, lunsigned v ); 72 void push_integer ( lua_State *L, linteger v ); 73 void push_number ( lua_State *L, lnumber v ); 74 void push_bool ( lua_State *L, bool v ); 75 void push_string ( lua_State *L, const std::string& s ); 76 void push_cstring ( lua_State *L, const char* s ); 77 void push_pointer ( lua_State *L, void* p ); 78 void push_ref_object ( lua_State *L, ref object ); 63 79 64 80 lunsigned to_unsigned ( lua_State *L, int index ); … … 137 153 static std::string to( lua_State *L, int index ) { return detail::to_string( L, index ); } 138 154 static std::string to( lua_State *L, int index, const std::string& def ) { return detail::to_string( L, index, def ); } 155 }; 156 157 template <> 158 struct pass_traits<ref> 159 { 160 static void push( lua_State *L, ref s ) { detail::push_ref_object( L, s ); } 139 161 }; 140 162 -
trunk/nv/object.hh
r257 r265 165 165 166 166 protected: 167 string m_id; ///< id type of the object168 string m_name; ///< name of the object169 uid m_uid; ///< uid of the object170 int m_lua_index; ///< lua reference171 int m_lua_proto_index; ///< lua reference172 object* m_parent; ///< pointer to parent173 list m_children; ///< children objects174 size_t m_child_count; ///< number of children167 string m_id; ///< id type of the object 168 string m_name; ///< name of the object 169 uid m_uid; ///< uid of the object 170 int m_lua_index; ///< lua reference 171 int m_lua_proto_index; ///< lua reference 172 object* m_parent; ///< pointer to parent 173 list m_children; ///< children objects 174 size_t m_child_count; ///< number of children 175 175 }; 176 176 -
trunk/src/lua/lua_map_area.cc
r263 r265 233 233 } 234 234 235 void nv::lua::register_map_area_instance( lua_State* L, intobject_index, map_area* area )236 { 237 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index );235 void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area ) 236 { 237 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() ); 238 238 lua_pushstring( L, "__map_area_ptr" ); 239 239 lua_pushlightuserdata( L, (map_area*)area ); -
trunk/src/lua/lua_state.cc
r263 r265 328 328 } 329 329 330 lua::ref erencelua::state::register_object( void* o, const char* lua_name )331 { 332 if ( o == nullptr ) return ref_none;330 lua::ref lua::state::register_object( void* o, const char* lua_name ) 331 { 332 if ( o == nullptr ) return lua::ref( lua::ref::none ); 333 333 stack_guard guard( this ); 334 334 lua_getglobal( m_state, lua_name ); … … 338 338 } 339 339 deep_pointer_copy( -1, o ); 340 return lua L_ref( m_state, LUA_REGISTRYINDEX);341 } 342 343 lua::ref erencelua::state::register_proto( const char* id, const char* storage )340 return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) ); 341 } 342 343 lua::ref lua::state::register_proto( const char* id, const char* storage ) 344 344 { 345 345 stack_guard guard( this ); … … 354 354 NV_THROW( runtime_error, std::string( id ) + " not found in " + std::string( storage ) + " storage!" ); 355 355 } 356 return lua L_ref( m_state, LUA_REGISTRYINDEX);356 return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) ); 357 357 } 358 358 … … 369 369 } 370 370 371 void lua::state::unregister_object( ref erenceobject_index )372 { 373 if ( object_index == ref_nil) return;371 void lua::state::unregister_object( ref object_index ) 372 { 373 if ( !object_index.is_valid() ) return; 374 374 stack_guard guard( this ); 375 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );375 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() ); 376 376 lua_pushstring( m_state, "__ptr" ); 377 377 lua_pushboolean( m_state, false ); 378 378 lua_rawset( m_state, -3 ); 379 379 lua_pop( m_state, 1 ); 380 luaL_unref( m_state, LUA_REGISTRYINDEX, object_index );380 luaL_unref( m_state, LUA_REGISTRYINDEX, object_index.get() ); 381 381 } 382 382 … … 419 419 } 420 420 421 void nv::lua::state::store_metadata( ref erenceobject_index, const std::string& metaname, void* pointer )422 { 423 if ( object_index == ref_nil) return;424 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );421 void nv::lua::state::store_metadata( ref object_index, const std::string& metaname, void* pointer ) 422 { 423 if ( !object_index.is_valid() ) return; 424 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() ); 425 425 lua_pushstring( m_state, metaname.c_str() ); 426 426 lua_pushlightuserdata( m_state, pointer ); -
trunk/src/lua/lua_values.cc
r262 r265 40 40 } 41 41 42 void nv::lua::detail::push_nil( lua_State *L ) 43 { 44 lua_pushnil( L ); 45 } 46 42 47 void nv::lua::detail::push_unsigned( lua_State *L, lunsigned v ) 43 48 { … … 74 79 lua_pushlightuserdata( L, p ); 75 80 } 81 82 void nv::lua::detail::push_ref_object ( lua_State *L, ref object ) 83 { 84 lua_rawgeti( L, LUA_REGISTRYINDEX, object.get() ); 85 } 86 76 87 77 88 lunsigned nv::lua::detail::to_unsigned( lua_State *L, int index ) -
trunk/src/object.cc
r257 r265 18 18 , m_name() 19 19 , m_uid(0) 20 , m_lua_index(lua::ref _none)21 , m_lua_proto_index(lua::ref _none)20 , m_lua_index(lua::ref::none) 21 , m_lua_proto_index(lua::ref::none) 22 22 , m_parent( nullptr ) 23 23 , m_children() -
trunk/src/root.cc
r264 r265 22 22 destroy_children( o ); 23 23 o->detach(); 24 if ( m_lua_state && o->m_lua_index != lua::ref _none )24 if ( m_lua_state && o->m_lua_index != lua::ref::none ) 25 25 { 26 m_lua_state->unregister_object( o->m_lua_index);26 m_lua_state->unregister_object( lua::ref( o->m_lua_index ) ); 27 27 } 28 28 if ( m_uid_store && o->m_uid != 0 ) … … 47 47 if ( lua_name != nullptr ) 48 48 { 49 o->m_lua_index = m_lua_state->register_object( o, lua_name ) ;49 o->m_lua_index = m_lua_state->register_object( o, lua_name ).get(); 50 50 } 51 51 if ( storage != nullptr ) 52 52 { 53 o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage ) ;53 o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage ).get(); 54 54 } 55 55 }
Note: See TracChangeset
for help on using the changeset viewer.