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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.