Changeset 431 for trunk


Ignore:
Timestamp:
07/21/15 13:31:23 (10 years ago)
Author:
epyon
Message:
  • hash storage type
  • string hash storage type
  • several minor fixes
  • more cleanups needed
Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/types.hh

    r429 r431  
    5656        struct type_field
    5757        {
    58                 uint64  name;     //!< name of the field
     58                shash64     name;     //!< name of the field
    5959                type_hash   hash; //!< typeinfo for later retrieval of type
    6060                type_entry* type;     //!< pointer to field type
     
    6565        struct type_enum
    6666        {
    67                 uint64 name;
    68                 sint32 value;
     67                shash64 name;
     68                sint32  value;
    6969        };
    7070
     
    146146                }
    147147
    148                 string_view resolve_name( uint64 name_hash )
     148                string_view resolve_name( shash64 name_hash )
    149149                {
    150150                        return m_names[name_hash];
  • trunk/nv/engine/resource_system.hh

    r399 r431  
    3737                virtual void clear() { m_names.clear(); }
    3838                void load_all();
    39                 resource_id load_resource( const std::string& id );
     39                resource_id load_resource( const string_view& id );
    4040                virtual ~resource_manager_base() {}
    4141        protected:
     
    4343
    4444                lua::state* m_lua;
    45                 unordered_map< std::string, resource_id > m_names;
     45                hashed_table< shash64, resource_id > m_names;
    4646        };
    4747
     
    5555                        return ( id < m_data.size() ? m_data[ id ] : T() );
    5656                }
    57                 T get_resource( const std::string& id )
     57                T get_resource( const string_view& id )
    5858                {
    5959                        auto m = m_names.find( id );
     
    9393        public:
    9494                explicit resource_system() : m_lua_state( nullptr ) { m_managers.push_back(nullptr); }
    95                 resource_type_id register_resource_type( const std::string& name, resource_manager_base* manager );
    96                 resource_type_id get_resource_type_id( const std::string& name ) const;
     95                resource_type_id register_resource_type( const string_view& name, resource_manager_base* manager );
     96                resource_type_id get_resource_type_id( const string_view& name ) const;
    9797                void initialize( lua::state* a_lua_state );
    9898                virtual ~resource_system();
    9999        protected:
    100100                vector< resource_manager_base* >     m_managers;
    101                 unordered_map< std::string, resource_id > m_manager_names;
     101                unordered_map< uint64, resource_id > m_manager_names;
    102102                lua::state* m_lua_state;
    103103        };
  • trunk/nv/formats/nmd_loader.hh

    r428 r431  
    5656                uint16   children;
    5757                uint32   size;
    58                 uint64   name;
     58                shash64  name;
    5959                mat4     transform;
    6060                sint16   parent_id;
  • trunk/nv/gfx/skeletal_mesh.hh

    r430 r431  
    3838        {
    3939        public:
    40                 skeletal_animation_entry_cpu( uint64 name, const mesh_nodes_data* a_animation, bool a_looping )
     40                skeletal_animation_entry_cpu( shash64 name, const mesh_nodes_data* a_animation, bool a_looping )
    4141                        : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_node_data( a_animation )
    4242                {
    4343                        initialize();
    4444                }
    45                 skeletal_animation_entry_cpu( uint64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )
     45                skeletal_animation_entry_cpu( shash64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )
    4646                        : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_node_data( a_animation )
    4747                {
     
    7575        {
    7676        public:
    77                 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, bool a_looping )
     77                skeletal_animation_entry_gpu( shash64 name, const mesh_nodes_data* anim, bool a_looping )
    7878                        : animation_entry( name, a_looping, anim->get_frame_rate(), 0.0f, anim->get_duration() )
    7979                        , m_node_data( anim )
     
    8282                }
    8383
    84                 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping )
     84                skeletal_animation_entry_gpu( shash64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping )
    8585                        : animation_entry( name, a_looping, anim->get_frame_rate(), time_start, time_end )
    8686                        , m_node_data( anim )
  • trunk/nv/interface/animated_mesh.hh

    r423 r431  
    2525        {
    2626        public:
    27                 animation_entry( uint64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ),
     27                animation_entry( shash64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ),
    2828                m_start( a_start ), m_end( a_end ), m_duration( m_end - m_start ), m_material_idx(0) {}
    29                 uint64 get_name() const { return m_name; }
     29                shash64 get_name() const { return m_name; }
    3030                uint32 get_frame_rate() const { return m_frame_rate; }
    3131                float get_duration() const { return m_duration; }
     
    4747                virtual ~animation_entry() {}
    4848        protected:
    49                 uint64 m_name;
    50                 bool   m_looping;
    51                 uint32 m_frame_rate;
    52                 float  m_start;
    53                 float  m_end;
    54                 float  m_duration;
    55                 uint32 m_material_idx;
     49                shash64 m_name;
     50                bool    m_looping;
     51                uint32  m_frame_rate;
     52                float   m_start;
     53                float   m_end;
     54                float   m_duration;
     55                uint32  m_material_idx;
    5656        };
    5757
  • trunk/nv/interface/data_channel.hh

    r424 r431  
    9191                        for ( uint32 c = 0; c < other.m_size; ++c )
    9292                                m_channels[c] = move( other.m_channels[c] );
    93                         m_size      = other.m_size;
    94                         m_parent_id = other.m_parent_id;
    95                         m_transform = other.m_transform;
    96                         m_name      = other.m_name;
     93                        m_size       = other.m_size;
     94                        m_parent_id  = other.m_parent_id;
     95                        m_transform  = other.m_transform;
     96                        m_name       = other.m_name;
    9797                        other.m_size = 0;
    9898                }
     
    209209                const_iterator end()   const { return &m_channels[ m_size ]; }
    210210
    211                 uint64 get_name() const { return m_name; }
     211                shash64 get_name() const { return m_name; }
    212212                sint16 get_parent_id() const { return m_parent_id; }
    213213                const mat4& get_transform() const { return m_transform; }
     
    218218                {
    219219                        m_size      = 0;
    220                         m_name      = 0;
    221220                        m_parent_id = -1;
    222221                }
     
    224223                raw_data_channel m_channels[4];
    225224
    226                 uint32 m_size;
    227                 uint64 m_name;
    228                 sint16 m_parent_id;
    229                 mat4   m_transform;
     225                uint32  m_size;
     226                shash64 m_name;
     227                sint16  m_parent_id;
     228                mat4    m_transform;
    230229        };
    231230
  • trunk/nv/interface/data_channel_access.hh

    r427 r431  
    144144                const mat4& get_transform() const { return m_set->m_transform; }
    145145
    146                 void set_name( uint64 name ) {  m_set->m_name = name; }
    147                 uint64 get_name() const { return m_set->m_name; }
     146                void set_name( shash64 name ) {  m_set->m_name = name; }
     147                shash64 get_name() const { return m_set->m_name; }
    148148
    149149                void set_parent_id( sint16 name ) { m_set->m_parent_id = name; }
  • trunk/nv/interface/map_area.hh

    r406 r431  
    1616#include <nv/core/position.hh>
    1717#include <nv/stl/string.hh>
    18 #include <string>
    1918
    2019namespace nv
     
    2726                virtual uint32 get_cell( const position& p ) const = 0;
    2827                virtual void set_cell( const position& p, uint32 value ) = 0;
    29                 virtual uint32 string_to_id( const std::string& ) const { return 0; }
    30                 virtual std::string id_to_string( uint32 ) const { return std::string(); }
     28                virtual uint32 string_to_id( const string_view& ) const { return 0; }
     29                virtual string_view id_to_string( uint32 ) const { return string_view(); }
    3130                virtual dimension get_size() const = 0;
    3231                virtual position get_shift() const { return position(); }
     
    4847                virtual dimension get_size() const { return m_area.get_size(); }
    4948                virtual position get_shift() const { return m_area.ul + m_map_area->get_shift(); }
    50                 virtual uint32 string_to_id( const std::string& s ) const { return m_map_area->string_to_id( s ); }
    51                 virtual std::string id_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); }
     49                virtual uint32 string_to_id( const string_view& s ) const { return m_map_area->string_to_id( s ); }
     50                virtual string_view id_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); }
    5251        private:
    5352                map_area* m_map_area;
  • trunk/nv/interface/mesh_data.hh

    r430 r431  
    3232                typedef storage::const_iterator const_iterator;
    3333
    34                 explicit mesh_nodes_data( uint64 name )
     34                explicit mesh_nodes_data( shash64 name )
    3535                        : m_name( name ), m_frame_rate(0), m_duration(0.0f), m_flat( false )
    3636                {
    3737                }
    3838
    39                 explicit mesh_nodes_data( uint64 name, uint16 a_fps, float a_frames, bool a_flat )
     39                explicit mesh_nodes_data( shash64 name, uint16 a_fps, float a_frames, bool a_flat )
    4040                        : m_name( name ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat )
    4141                {
     
    5656                }
    5757
    58                 const data_channel_set* get_by_hash( uint64 h ) const
     58                const data_channel_set* get_by_hash( shash64 h ) const
    5959                {
    6060                        for ( auto data : m_data )
     
    6565                }
    6666
    67                 int get_index_by_hash( uint64 h ) const
     67                int get_index_by_hash( shash64 h ) const
    6868                {
    6969                        for ( uint32 i = 0; i < m_data.size(); ++i )
     
    8686                uint16 get_frame_rate() const { return m_frame_rate; }
    8787                float get_duration() const { return m_duration; }
    88                 void set_name( uint64 name ) { m_name = name; }
    89                 uint64 get_name() const { return m_name; }
     88                shash64 get_name() const { return m_name; }
    9089
    9190                ~mesh_nodes_data()
     
    9695        private:
    9796                vector< data_channel_set* > m_data;
    98                 uint64 m_name;
     97                shash64 m_name;
    9998                uint16  m_frame_rate;
    10099                float   m_duration;
  • trunk/nv/interface/mesh_loader.hh

    r428 r431  
    3737                virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 ) { return nullptr; }
    3838        protected:
    39                 inline uint64 make_name( const string_view& name )
     39                inline shash64 make_name( const string_view& name )
    4040                {
    41                         return m_strings ? m_strings->insert( name ) : name.get_hash< uint64 >();
     41                        return m_strings ? m_strings->insert( name ) : shash64( name.get_hash< uint64 >() );
    4242                }
    4343                string_table* m_strings;
  • trunk/nv/lua/lua_state.hh

    r426 r431  
    1515#include <nv/stl/flags.hh>
    1616#include <nv/stl/handle.hh>
     17#include <nv/stl/string_table.hh>
    1718#include <nv/stl/type_traits/function.hh>
    1819
     
    294295                        size_t get_size();
    295296                        bool has_field( string_view element );
    296                         uint64 get_string_hash_64( string_view element, uint64 defval = 0 );
     297                        shash64 get_string_hash_64( string_view element, uint64 defval = 0 );
     298                        shash64 get_string( string_view element, string_table& table, uint64 defval = 0 );
    297299                        std::string get_std_string( string_view element, string_view defval = string_view() );
    298300                        const_string get_string( string_view element, string_view defval = string_view() );
  • trunk/nv/stl/functional/hash.hh

    r428 r431  
    135135
    136136        template < typename H, typename T >
    137         constexpr H hash_value( const T& value )
    138         {
    139                 return hash<T, H>::get( value );
    140         }
    141 
    142         template < typename H, typename T >
    143137        constexpr H hash_combine( H seed, const T& h )
    144138        {
     
    168162        }
    169163
     164        template < typename H, typename Tag = void >
     165        class hash_value
     166        {
     167        public:
     168                typedef H hash_type;
     169                typedef H value_type;
     170                typedef hash_value< H, Tag > this_type;
     171
     172
     173                // TODO: enforce exact type?
     174                constexpr hash_value() : m_value( 0 ) {}
     175                constexpr explicit hash_value( hash_type value ) : m_value( value ) {}
     176                constexpr hash_value( const hash_value& ) = default;
     177
     178                constexpr bool valid() const { return m_value != 0; }
     179
     180                template < typename H, typename Tag >
     181                friend constexpr bool operator==( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs );
     182                template < typename H, typename Tag >
     183                friend constexpr bool operator!=( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs );
     184
     185                constexpr H value() const { return m_value; }
     186        protected:
     187                hash_type m_value;
     188        };
     189
     190        template < typename T >
     191        struct is_hash_value : is_template_base_of< T, hash_value > {};
     192
     193        template< typename T, typename H >
     194        struct hash< T, H,
     195                typename enable_if<
     196                        is_hash_value<T>::value &&
     197                        is_same< H, typename T::hash_type >::value,
     198                        void
     199                >::type > : detail::hash_base< T, H >
     200        {
     201                typedef H hash_type;
     202                static H get( const T& value )
     203                {
     204                        return value.value();
     205                }
     206                inline H operator()( const T& value ) const { return get( value ); }
     207        };
     208
     209        template < typename H, typename Tag >
     210        constexpr bool operator==( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs )
     211        {
     212                return lhs.m_value == rhs.m_value;
     213        }
     214
     215        template < typename H, typename Tag >
     216        constexpr bool operator!=( hash_value< H, Tag > lhs, hash_value< H, Tag > rhs )
     217        {
     218                return lhs.m_value != rhs.m_value;
     219        }
     220
     221        typedef hash_value< uint32 > hash32;
     222        typedef hash_value< uint64 > hash64;
    170223
    171224        template < typename T, typename H, bool StoreElement = true >
  • trunk/nv/stl/string.hh

    r410 r431  
    4242        //      string
    4343
    44         template<>
    45         struct hash< std::string, size_t >
    46         {
    47                 static size_t get( const std::string& value )
    48                 {
    49                         return hash_string< size_t >( value.c_str(), value.length() );
    50                 }
    51                 inline size_t operator()( const std::string& value ) const { return get( value ); }
     44        template< typename H >
     45        struct hash< std::string, H > : detail::hash_base< std::string, H >
     46        {
     47                static H get( const std::string& value )
     48                {
     49                        return hash_string< H >( value.c_str(), value.length() );
     50                }
     51                inline H operator()( const std::string& value ) const { return get( value ); }
    5252        };
    5353
     
    164164        template< typename T, typename H >
    165165        struct hash< T, H, typename enable_if< is_string_base<T>::value, void >::type >
     166                : detail::hash_base< T, H >
    166167        {
    167168                static H get( const T& value )
     
    615616        }
    616617
     618        struct string_hash_tag {};
     619
     620        template < typename H >
     621        class string_hash : public hash_value< H, string_hash_tag >
     622        {
     623        public:
     624                typedef H hash_type;
     625                typedef H value_type;
     626                typedef string_hash< H > this_type;
     627                typedef hash_value< H, string_hash_tag > inherited_type;
     628
     629                // TODO: enforce exact type?
     630                constexpr string_hash() : inherited_type() {}
     631                inline string_hash( const string_view& rhs ) : inherited_type( hash_string< H >( rhs.data(), rhs.size() ) ) {}
     632                template < typename S >
     633                inline string_hash( const string_base<S>& rhs ) : inherited_type( hash_string< H >( rhs.data(), rhs.size() ) ) {}
     634                constexpr string_hash( const char* str, size_t len ) : inherited_type( hash_string< H >( str, len ) ) {}
     635
     636                // Literal constructors
     637                template< size_t N >
     638                constexpr string_hash( char( &s )[N] ) : inherited_type( hash_string< H >( s, N - 1 ) ) {}
     639                template< size_t N >
     640                constexpr string_hash( const char( &s )[N] ) : inherited_type( hash_string< H >( s, N - 1 ) ) {}
     641
     642                constexpr explicit string_hash( hash_type value ) : inherited_type( value ) {}
     643                constexpr string_hash( const string_hash& value ) = default;
     644        };
     645
     646        typedef string_hash< uint32 > shash32;
     647        typedef string_hash< uint64 > shash64;
    617648}
    618649
  • trunk/nv/stl/string_table.hh

    r428 r431  
    2626        public:
    2727                typedef string_view value_type;
    28                 typedef uint64 key_type;
     28                typedef shash64 key_type;
    2929                typedef uint64 hash_type;
    3030                typedef uint32 size_type;
    3131                typedef uint16 length_type;
    32                 typedef unordered_map< key_type, size_type > indexer_type;
     32                typedef unordered_map< hash_type, size_type > indexer_type;
    3333                typedef vector< char > storage_type;
    3434                typedef indexer_type::const_iterator const_iterator;
     
    3939                key_type insert( const value_type& str )
    4040                {
    41                         key_type hash_value = str.get_hash< uint64 >();
     41                        hash_type hash_value = str.get_hash< uint64 >();
    4242                        insert( hash_value, str );
    43                         return hash_value;
     43                        return key_type( hash_value );
    4444                }
    4545
    4646                bool exists( key_type i ) const
    4747                {
    48                         return m_map.find( i ) != m_map.end();
     48                        return m_map.find( i.value() ) != m_map.end();
    4949                }
    5050
    5151                value_type at( key_type i ) const
    5252                {
    53                         const auto& it = m_map.find( i );
     53                        const auto& it = m_map.find( i.value() );
    5454                        NV_ASSERT_ALWAYS( it != m_map.end(), "Key not found in string_table!" );
    5555                        return extract_raw( it->second );
     
    5858                value_type operator[]( key_type i ) const
    5959                {
    60                         const auto& it = m_map.find( i );
     60                        const auto& it = m_map.find( i.value() );
    6161                        return it != m_map.end() ? extract_raw( it->second ) : value_type();
    6262                }
  • trunk/nv/stl/unordered_map.hh

    r408 r431  
    227227                typename Hash = hash< Key >,
    228228                typename KeyEqual = equal_to< Key >,
    229                 typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, size_t, KeyEqual, Hash >
     229                typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, typename Hash::result_type, KeyEqual, Hash >
    230230        >
    231231        class unordered_map
     
    324324        };
    325325
     326        // TODO: remove and make a proper hashed map
     327        template <
     328                typename Key,
     329                typename T,
     330                typename Hasher = hash< Key, typename Key::value_type >,
     331                typename KeyEqual = equal_to< Key >,
     332                typename HashEntryPolicy = hash_table_stl_map_policy< Key, T, typename Key::value_type, KeyEqual, Hasher >
     333        >
     334        class hashed_table
     335                : public hash_table<
     336                HashEntryPolicy,
     337                hash_table_no_extra_types_policy,
     338                hash_table_prime_rehash_policy,
     339                HashEntryPolicy
     340                >
     341        {
     342        public:
     343                typedef hash_table<
     344                        HashEntryPolicy,
     345                        hash_table_no_extra_types_policy,
     346                        hash_table_prime_rehash_policy,
     347                        HashEntryPolicy
     348                > base_type;
     349                typedef typename base_type::value_type                                           value_type;
     350                typedef typename base_type::pointer                                              pointer;
     351                typedef typename base_type::const_pointer                                        const_pointer;
     352                typedef typename base_type::reference                                            reference;
     353                typedef typename base_type::const_reference                                      const_reference;
     354                typedef typename base_type::iterator                                             iterator;
     355                typedef typename base_type::const_iterator                                       const_iterator;
     356                typedef typename base_type::size_type                                            size_type;
     357                typedef typename base_type::difference_type                                      difference_type;
     358                typedef typename base_type::key_type                                             key_type;
     359                typedef typename base_type::mapped_type                                          mapped_type;
     360                typedef typename base_type::node_type                                            node_type;
     361                typedef typename base_type::insert_return_type                                   insert_return_type;
     362                typedef Hasher                                                                   hasher;
     363                typedef KeyEqual                                                                 key_equal;
     364
     365                using base_type::base_type;
     366
     367                mapped_type& operator[]( const key_type& key )
     368                {
     369                        return ( *base_type::insert_key( key ).first ).second;
     370                }
     371        };
     372
     373
    326374}
    327375
  • trunk/src/engine/resource_system.cc

    r399 r431  
    1515}
    1616
    17 nv::resource_id nv::resource_manager_base::load_resource( const std::string& id )
     17nv::resource_id nv::resource_manager_base::load_resource( const string_view& id )
    1818{
    1919        lua::table_guard table( m_lua, lua::path( get_storage_name(), id ) );
     
    3232                lua::table_guard sub_table( table, i+1 );
    3333                resource_id rid = load_resource( sub_table );
    34                 if ( rid != 0 ) m_names[ sub_table.get_std_string("id") ] = rid;
     34                if ( rid != 0 ) m_names[ sub_table.get_string_hash_64("id") ] = rid;
    3535        }
    3636}
    3737
    38 nv::resource_type_id nv::resource_system::register_resource_type( const std::string& /*name*/, resource_manager_base* /*manager*/ )
     38nv::resource_type_id nv::resource_system::register_resource_type( const string_view& /*name*/, resource_manager_base* /*manager*/ )
    3939{
    4040        return 0;
    4141}
    4242
    43 nv::resource_type_id nv::resource_system::get_resource_type_id( const std::string& /*name*/ ) const
     43nv::resource_type_id nv::resource_system::get_resource_type_id( const string_view& /*name*/ ) const
    4444{
    4545        return 0;
  • trunk/src/formats/assimp_loader.cc

    r428 r431  
    288288        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    289289        mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) );
    290         unordered_map< uint64, uint16 > names;
     290        hashed_table< shash64, uint16 > names;
    291291        for ( unsigned int m = 0; m < m_mesh_count; ++m )
    292292        {
  • trunk/src/formats/md3_loader.cc

    r427 r431  
    420420        uint32 node_count = uint32( md3->header.num_tags );
    421421        if ( node_count == 0 ) return nullptr;
    422         mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0 );
     422        mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : shash64() );
    423423        for ( uint32 i = 0; i < node_count; ++i )
    424424        {
  • trunk/src/formats/nmd_loader.cc

    r428 r431  
    233233        sheader.children   = 0;
    234234        sheader.size       = strings.dump_size();
    235         sheader.name       = 0;
     235        sheader.name       = shash64();
    236236        sheader.parent_id  = -1;
    237237    sheader.attributes = 0;
  • trunk/src/gfx/skeletal_mesh.cc

    r430 r431  
    177177        {
    178178                const data_channel_set* bone = (*bones)[ bi ];
    179                 bone_names[ bone->get_name() ] = bi;
     179                bone_names[ bone->get_name().value() ] = bi;
    180180                m_offsets[bi] = bone->get_transform();
    181181        }
     
    186186                sint16 bone_id = -1;
    187187
    188                 auto bi = bone_names.find( node->get_name() );
     188                auto bi = bone_names.find( node->get_name().value() );
    189189                if ( bi != bone_names.end() )
    190190                {
  • trunk/src/lua/lua_map_area.cc

    r406 r431  
    137137{
    138138        nv::map_area* ma = to_map_area( L, 1 );
    139         lua_pushstring( L, ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ).c_str() );
     139        nv::string_view result( ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) );
     140        lua_pushlstring( L, result.data(), result.size() );
    140141        return 1;
    141142}
  • trunk/src/lua/lua_state.cc

    r426 r431  
    184184}
    185185
    186 uint64 nv::lua::table_guard::get_string_hash_64( string_view element, uint64 defval /*= 0 */ )
     186shash64 nv::lua::table_guard::get_string_hash_64( string_view element, uint64 defval /*= 0 */ )
    187187{
    188188        lua_getfield( m_state, -1, element.data() );
     
    196196        }
    197197        lua_pop( m_state, 1 );
    198         return result;
     198        return shash64( result );
     199}
     200
     201shash64 nv::lua::table_guard::get_string( string_view element, string_table& table, uint64 defval /*= 0 */ )
     202{
     203        lua_getfield( m_state, -1, element.data() );
     204        size_t l = 0;
     205        const char* str = nullptr;
     206        uint64 result = defval;
     207        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     208        {
     209                str = lua_tolstring( m_state, -1, &l );
     210                result = table.insert( string_view( str, l ) ).value();
     211        }
     212        lua_pop( m_state, 1 );
     213        return shash64( result );
    199214}
    200215
Note: See TracChangeset for help on using the changeset viewer.