Index: trunk/src/lua/lua_flags.cc
===================================================================
--- trunk/src/lua/lua_flags.cc	(revision 209)
+++ trunk/src/lua/lua_flags.cc	(revision 209)
@@ -0,0 +1,32 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/lua/lua_flags.hh"
+
+#include "nv/lua/lua_raw.hh"
+#include "nv/string.hh"
+
+
+void nv::lua::detail::read_flags( lua_State* L, int index, uint8* data, uint32 count )
+{
+	nlua_toflags( L, index, data, count );
+}
+
+void nv::lua::detail::push_flags( lua_State* L, uint8* data, uint32 count )
+{
+	// TODO : this can be optimized
+	lua_createtable( L, 0, 0 );
+	for ( uint32 c = 0; c < count; ++c )
+	{
+		uint32 idx = c / 8;
+		uint32 pos = c % 8;
+		if ( ( data[ idx ] & ( 1 << static_cast< uint8 >( pos ) ) ) != 0 )
+		{
+			lua_pushboolean( L, true );
+			lua_rawseti( L, -2, c );
+		}
+	}
+}
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 208)
+++ trunk/src/lua/lua_state.cc	(revision 209)
@@ -251,17 +251,4 @@
 }
 
-void lua::table_guard::get_raw_flags( const std::string& element, uint8* data, uint32 count )
-{
-	lua_getfield( m_state, -1, element.c_str() );
-	if ( lua_type( m_state, -1 ) != LUA_TTABLE )
-	{
-		lua_pop( m_state, 1 );
-		return;
-	}
-	nlua_toflags( m_state, -1, data, count );
-	lua_pop( m_state, 1 );
-}
-
-
 void lua::state::log_stack()
 {
