source: trunk/src/lua/lua_flags.cc @ 368

Last change on this file since 368 was 368, checked in by epyon, 10 years ago
  • massive restructuring
  • detail::data_base class for container/reference class base
File size: 817 bytes
Line 
1// Copyright (C) 2012-2014 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/lua/lua_flags.hh"
8
9#include "nv/lua/lua_raw.hh"
10#include "nv/stl/string.hh"
11
12
13void nv::lua::detail::read_flags( lua_State* L, int index, uint8* data, uint32 count )
14{
15        nlua_toflags( L, index, data, count );
16}
17
18void nv::lua::detail::push_flags( lua_State* L, uint8* data, uint32 count )
19{
20        // TODO : this can be optimized
21        lua_createtable( L, 0, 0 );
22        for ( int c = 0; c < static_cast< int >( count ); ++c )
23        {
24                int idx = c / 8;
25                int pos = c % 8;
26                if ( ( data[ idx ] & ( 1 << static_cast< uint8 >( pos ) ) ) != 0 )
27                {
28                        lua_pushboolean( L, true );
29                        lua_rawseti( L, -2, c );
30                }
31        }
32}
Note: See TracBrowser for help on using the repository browser.