Changeset 215
- Timestamp:
- 09/09/13 21:14:19 (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/lua/lua_flags.hh
r209 r215 40 40 void read_flags( lua_State* L, int index, flags<SIZE,T>& flags ) 41 41 { 42 read_flags( L, flags.data(), flags.size() );42 read_flags( L, index, flags.data(), flags.size() ); 43 43 } 44 44 -
trunk/nv/lua/lua_state.hh
r213 r215 16 16 #include <nv/common.hh> 17 17 #include <nv/flags.hh> 18 #include <nv/types.hh> 18 19 19 20 #include <nv/lua/lua_path.hh> … … 177 178 explicit state( bool load_libs = false ); 178 179 explicit state( lua_State* state ); 180 virtual ~state(); 179 181 bool do_string( const std::string& code, const std::string& name, int rvalues = 0 ); 180 182 bool do_stream( std::istream& stream, const std::string& name ); … … 185 187 reference register_object( object * o ); 186 188 reference register_object( object * o, const char* lua_name ); 189 190 template< typename TYPE > 191 type_entry& register_type( const char* name ) 192 { 193 m_type_database->create_type<TYPE>( name ); 194 } 195 196 template< typename TYPE, int SIZE > 197 void register_enum( const char* name, const char* prefix, type_enum (&init_enums)[SIZE] ) 198 { 199 m_type_database->create_type<TYPE>( name ).enums( init_enums ); 200 register_enum_values( name, prefix ); 201 } 202 void register_enum_values( const std::string& name, const std::string& prefix = std::string() ); 203 187 204 void store_metadata( object* o, const std::string& metaname, void* pointer ); 188 205 void unregister_object( object * o ); … … 191 208 void register_object_method( const char* lua_name, const char* name ) 192 209 { 193 register_native_object_method( lua_name, name, detail::object_method_wrapper< typename memfn_class_type<F>, F, f > ); 194 } 195 void register_enum( type_database* db, const std::string& name, const std::string& prefix = std::string() ); 210 register_native_object_method( lua_name, name, detail::object_method_wrapper< typename memfn_class_type<F>::type, F, f > ); 211 } 196 212 operator lua_State*() { return m_state; } 213 type_database* get_type_database() { return m_type_database; } 197 214 private: 198 215 int load_string( const std::string& code, const std::string& name ); … … 201 218 int do_current( const std::string& name, int rvalues = 0 ); 202 219 void deep_pointer_copy( int index, void* obj ); 220 private: 221 type_database* m_type_database; 203 222 }; 204 223 -
trunk/nv/root.hh
r143 r215 19 19 { 20 20 public: 21 root() : object( nullptr, "" ), m_ type_database( nullptr ), m_lua_state( nullptr ), m_uid_store( nullptr ) { m_root = this; }21 root() : object( nullptr, "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) { m_root = this; } 22 22 virtual void child_added( object* ) {} 23 23 virtual void child_removed( object* ) {} 24 type_database* get_type_database() const { return m_type_database; }25 24 lua::state* get_lua_state() const { return m_lua_state; } 26 25 uid_store* get_uid_store() const { return m_uid_store; } 27 26 virtual ~root() { destroy_children(); } 28 27 protected: 29 type_database* m_type_database;30 28 lua::state* m_lua_state; 31 29 uid_store* m_uid_store; -
trunk/src/lua/lua_flags.cc
r209 r215 20 20 // TODO : this can be optimized 21 21 lua_createtable( L, 0, 0 ); 22 for ( uint32 c = 0; c < count; ++c )22 for ( int c = 0; c < static_cast< int >( count ); ++c ) 23 23 { 24 uint32idx = c / 8;25 uint32pos = c % 8;24 int idx = c / 8; 25 int pos = c % 8; 26 26 if ( ( data[ idx ] & ( 1 << static_cast< uint8 >( pos ) ) ) != 0 ) 27 27 { -
trunk/src/lua/lua_state.cc
r213 r215 32 32 } 33 33 34 lua::state::state( lua_State* state ) : state_wrapper( state, false ) 35 { 36 37 } 38 39 lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ) 34 lua::state::state( lua_State* state ) : state_wrapper( state, false ), m_type_database( nullptr ) 35 { 36 37 } 38 39 lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ), m_type_database( nullptr ) 40 40 { 41 41 load_lua_library(); … … 49 49 if ( load_libs ) 50 50 { 51 m_type_database = new type_database(); 51 52 stack_guard guard( this ); 52 53 static const luaL_Reg lualibs[] = … … 290 291 lua::reference lua::state::register_object( object * o ) 291 292 { 292 if ( o == nullptr ) return ref_none; 293 type_database *db = o->get_root()->get_type_database(); 294 if ( db == nullptr ) return ref_none; 295 type_entry* t = db->get_type(typeid(*o)); 293 if ( o == nullptr || m_type_database == nullptr ) return ref_none; 294 type_entry* t = m_type_database->get_type(typeid(*o)); 296 295 if ( t == nullptr ) return ref_none; 297 296 return register_object( o, t->name.c_str() ); … … 359 358 } 360 359 361 void lua::state::register_enum ( type_database* db,const std::string& name, const std::string& prefix /*= std::string() */ )362 { 363 type_entry* et = db->get_type( name );360 void lua::state::register_enum_values( const std::string& name, const std::string& prefix /*= std::string() */ ) 361 { 362 type_entry* et = m_type_database->get_type( name ); 364 363 365 364 for ( const auto& entry : et->enum_list ) … … 388 387 } 389 388 389 nv::lua::state::~state() 390 { 391 if (m_type_database != nullptr ) 392 { 393 delete m_type_database; 394 } 395 } 396 390 397 bool nv::lua::state_wrapper::is_defined( const path& p, bool global ) 391 398 {
Note: See TracChangeset
for help on using the changeset viewer.