Changeset 162


Ignore:
Timestamp:
07/15/13 20:13:27 (12 years ago)
Author:
epyon
Message:
  • flags - flags support, essentially a std::bitset implementation with .data() method and enum class support
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/array2d.hh

    r141 r162  
    184184                inline reference operator[] ( const ivec2& c )
    185185                {
    186                         NV_ASSERT( x >= 0 && y >= 0 && x < m_size.x && y < m_size.y, "Bad parameters passed to array2d[]" );
     186                        NV_ASSERT( c.x >= 0 && c.y >= 0 && c.x < m_size.x && c.y < m_size.y, "Bad parameters passed to array2d[]" );
    187187                        return m_data[ c.y * m_size.x + c.x ];
    188188                }
  • trunk/nv/lua/lua_raw.hh

    r121 r162  
    1111#include <istream>
    1212#include <string>
    13 #include <bitset>
    1413#include <map>
     14
     15void nlua_toflags_flat( lua_State *L, int index, nv::uint8* data, nv::uint32 count );
     16void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count );
     17void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count );
    1518
    1619std::string nlua_typecontent( lua_State* L, int idx );
  • trunk/nv/lua/lua_state.hh

    r121 r162  
    1111#include <map>
    1212#include <nv/common.hh>
     13#include <nv/flags.hh>
    1314#include <string>
    1415
     
    5253                        double get_double( const std::string& element, double defval = 0.0 );
    5354                        bool get_boolean( const std::string& element, bool defval = false );
    54                 public:
     55
     56                        template< uint32 SIZE, typename T >
     57                        flags< SIZE, T > get_flags( const std::string& element )
     58                        {
     59                                flags< SIZE, T > result;
     60                                get_raw_flags( element, result.data(), result.size() );
     61                                return result;
     62                        }
     63
     64                        template< uint32 SIZE, typename T >
     65                        void load_flags( const std::string& element, flags< SIZE, T >& flags )
     66                        {
     67                                get_raw_flags( element, flags.data(), flags.size() );
     68                        }
     69                private:
     70                        void get_raw_flags( const std::string& element, uint8* data, uint32 count );
     71
    5572                        state* L;
    5673                        stack_guard m_guard;
  • trunk/src/lua/lua_raw.cc

    r121 r162  
    188188        lua_pop( L, 1 );
    189189}
     190
     191void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
     192{
     193        index = lua_absindex( L, index );
     194        nv::uint32 flag;
     195        if ( lua_istable( L, index ) )
     196        {
     197                lua_pushnil( L );
     198                while ( lua_next( L, index ) != 0 )
     199                {
     200                        if ( lua_type( L, -1 ) == LUA_TBOOLEAN )
     201                                flag = static_cast< nv::uint32 >( lua_tointeger( L ,-2 ) );
     202                        else
     203                                flag = static_cast< nv::uint32 >( lua_tointeger( L ,-1 ) );
     204                        lua_pop( L, 1 );
     205                        if ( flag < count )
     206                        {
     207                                data[ flag / 8 ] |= ( 1 << static_cast< nv::uint8 >( flag % 8 ) );
     208                        }
     209                }
     210        }
     211}
     212
     213void nlua_toflags_set( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
     214{
     215        index = lua_absindex( L, index );
     216        nv::uint32 flag;
     217        if ( lua_istable( L, index ) )
     218        {
     219                lua_pushnil( L );
     220                while ( lua_next( L, index ) != 0 )
     221                {
     222                        flag = static_cast< nv::uint32 >( lua_tointeger( L ,-2 ) );
     223                        lua_pop( L, 1 );
     224                        if ( flag < count )
     225                        {
     226                                data[ flag / 8 ] |= ( 1 << static_cast< nv::uint8 >( flag % 8 ) );
     227                        }
     228                }
     229        }
     230}
     231
     232void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
     233{
     234        index = lua_absindex( L, index );
     235        nv::uint32 flag;
     236        if ( lua_istable( L, index ) )
     237        {
     238                lua_pushnil( L );
     239                while ( lua_next( L, index ) != 0 )
     240                {
     241                        flag = static_cast< nv::uint32 >( lua_tointeger( L ,-1 ) );
     242                        lua_pop( L, 1 );
     243                        if ( flag < count )
     244                        {
     245                                data[ flag / 8 ] |= ( 1 << static_cast< nv::uint8 >( flag % 8 ) );
     246                        }
     247                }
     248        }
     249}
  • trunk/src/lua/lua_state.cc

    r121 r162  
    279279}
    280280
     281void lua::table_guard::get_raw_flags( const std::string& element, uint8* data, uint32 count )
     282{
     283        lua_getfield( L->L, -1, element.c_str() );
     284        if ( lua_type( L->L, -1 ) != LUA_TTABLE )
     285        {
     286                lua_pop( L->L, 1 );
     287                return;
     288        }
     289        nlua_toflags( L->L, -1, data, count );
     290        lua_pop( L->L, 1 );
     291}
     292
     293
    281294void lua::state::log_stack()
    282295{
Note: See TracChangeset for help on using the changeset viewer.