Changeset 215


Ignore:
Timestamp:
09/09/13 21:14:19 (12 years ago)
Author:
epyon
Message:
  • root - no longer holds a type_database
  • lua - lua::state has it's own type_database
  • lua - convinience function for registering enums
  • cleanup of clang errors and warnings
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/lua/lua_flags.hh

    r209 r215  
    4040                        void read_flags( lua_State* L, int index, flags<SIZE,T>& flags )
    4141                        {
    42                                 read_flags( L, flags.data(), flags.size() );
     42                                read_flags( L, index, flags.data(), flags.size() );
    4343                        }
    4444
  • trunk/nv/lua/lua_state.hh

    r213 r215  
    1616#include <nv/common.hh>
    1717#include <nv/flags.hh>
     18#include <nv/types.hh>
    1819
    1920#include <nv/lua/lua_path.hh>
     
    177178                        explicit state( bool load_libs = false );
    178179                        explicit state( lua_State* state );
     180                        virtual ~state();
    179181                        bool do_string( const std::string& code, const std::string& name, int rvalues = 0 );
    180182                        bool do_stream( std::istream& stream, const std::string& name );
     
    185187                        reference register_object( object * o );
    186188                        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
    187204                        void store_metadata( object* o, const std::string& metaname, void* pointer );
    188205                        void unregister_object( object * o );
     
    191208                        void register_object_method( const char* lua_name, const char* name )
    192209                        {
    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                        }
    196212                        operator lua_State*() { return m_state; }
     213                        type_database* get_type_database() { return m_type_database; }
    197214                private:
    198215                        int load_string( const std::string& code, const std::string& name );
     
    201218                        int do_current( const std::string& name, int rvalues = 0 );
    202219                        void deep_pointer_copy( int index, void* obj );
     220                private:
     221                        type_database* m_type_database;
    203222                };
    204223
  • trunk/nv/root.hh

    r143 r215  
    1919        {
    2020        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; }
    2222                virtual void child_added( object* ) {}
    2323                virtual void child_removed( object* ) {}
    24                 type_database* get_type_database() const { return m_type_database; }
    2524                lua::state*    get_lua_state()     const { return m_lua_state; }
    2625                uid_store*     get_uid_store()     const { return m_uid_store; }
    2726                virtual ~root() { destroy_children(); }
    2827        protected:
    29                 type_database* m_type_database;
    3028                lua::state*    m_lua_state;
    3129                uid_store*     m_uid_store;
  • trunk/src/lua/lua_flags.cc

    r209 r215  
    2020        // TODO : this can be optimized
    2121        lua_createtable( L, 0, 0 );
    22         for ( uint32 c = 0; c < count; ++c )
     22        for ( int c = 0; c < static_cast< int >( count ); ++c )
    2323        {
    24                 uint32 idx = c / 8;
    25                 uint32 pos = c % 8;
     24                int idx = c / 8;
     25                int pos = c % 8;
    2626                if ( ( data[ idx ] & ( 1 << static_cast< uint8 >( pos ) ) ) != 0 )
    2727                {
  • trunk/src/lua/lua_state.cc

    r213 r215  
    3232}
    3333
    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 )
     34lua::state::state( lua_State* state ) : state_wrapper( state, false ), m_type_database( nullptr )
     35{
     36
     37}
     38
     39lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ), m_type_database( nullptr )
    4040{
    4141        load_lua_library();
     
    4949        if ( load_libs )
    5050        {
     51                m_type_database = new type_database();
    5152                stack_guard guard( this );
    5253                static const luaL_Reg lualibs[] =
     
    290291lua::reference lua::state::register_object( object * o )
    291292{
    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));
    296295        if ( t == nullptr ) return ref_none;
    297296        return register_object( o, t->name.c_str() );
     
    359358}
    360359
    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 );
     360void 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 );
    364363
    365364        for ( const auto& entry : et->enum_list )
     
    388387}
    389388
     389nv::lua::state::~state()
     390{
     391        if (m_type_database != nullptr )
     392        {
     393                delete m_type_database;
     394        }
     395}
     396
    390397bool nv::lua::state_wrapper::is_defined( const path& p, bool global )
    391398{
Note: See TracChangeset for help on using the changeset viewer.