Last change
on this file since 212 was
209,
checked in by epyon, 12 years ago
|
- lua_flags - dedicated flags module and lua type passing support
- minor cleanups
|
File size:
817 bytes
|
Rev | Line | |
---|
[209] | 1 | // Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
|
---|
| 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/string.hh"
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | void nv::lua::detail::read_flags( lua_State* L, int index, uint8* data, uint32 count )
|
---|
| 14 | {
|
---|
| 15 | nlua_toflags( L, index, data, count );
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void 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 ( uint32 c = 0; c < count; ++c )
|
---|
| 23 | {
|
---|
| 24 | uint32 idx = c / 8;
|
---|
| 25 | uint32 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.