Index: /trunk/nv/lua/lua_area.hh
===================================================================
--- /trunk/nv/lua/lua_area.hh	(revision 208)
+++ /trunk/nv/lua/lua_area.hh	(revision 209)
@@ -38,5 +38,4 @@
 		{
 			static void push( lua_State *L, const rectangle& p ) { detail::push_area( L, p ); }
-			static void pop( lua_State *L, rectangle& p ) { p = detail::to_area( L, -1 ); detail::pop_and_discard( L, 1 ); }
 			static rectangle to( lua_State *L, int index ) { return detail::to_area( L, index ); }
 		};
Index: /trunk/nv/lua/lua_flags.hh
===================================================================
--- /trunk/nv/lua/lua_flags.hh	(revision 209)
+++ /trunk/nv/lua/lua_flags.hh	(revision 209)
@@ -0,0 +1,58 @@
+// 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
+#ifndef NV_LUA_FLAGS_HH
+#define NV_LUA_FLAGS_HH
+
+#include <nv/common.hh>
+#include <nv/flags.hh>
+#include <nv/lua/lua_state.hh>
+#include <nv/lua/lua_values.hh>
+
+namespace nv
+{
+	namespace lua
+	{
+//		void register_flags( lua_State* L );
+
+		namespace detail
+		{
+			void read_flags( lua_State* L, int index, uint8* data, uint32 count );
+			void push_flags( lua_State* L, uint8* data, uint32 count );
+
+			template< uint32 SIZE, typename T >
+			void push_flags( lua_State* L, const flags<SIZE,T>& f ) 
+			{ 
+				push_flags( L, f.data(), f.size() );
+			}
+
+			template< uint32 SIZE, typename T >
+			flags<SIZE,T> to_flags( lua_State* L, int index ) 
+			{ 
+				flags<SIZE,T> result;
+				read_flags( L, index, result.data(), result.size() );
+				return result;
+			}
+
+			template< uint32 SIZE, typename T >
+			void read_flags( lua_State* L, int index, flags<SIZE,T>& flags ) 
+			{ 
+				read_flags( L, flags.data(), flags.size() );
+			}
+
+		}
+
+		template< uint32 SIZE, typename T >
+		struct pass_traits< flags< SIZE, T > >
+		{
+			typedef flags< SIZE, T > value_type;
+			static void push( lua_State *L, const flags< SIZE, T >& f ) { detail::push_flags( L, f ); }
+			static value_type to( lua_State *L, int index ) { return detail::to_flags< SIZE, T >( L, index ); }
+		};
+
+	}
+}
+
+#endif // NV_LUA_FLAGS_HH
Index: /trunk/nv/lua/lua_state.hh
===================================================================
--- /trunk/nv/lua/lua_state.hh	(revision 208)
+++ /trunk/nv/lua/lua_state.hh	(revision 209)
@@ -203,21 +203,5 @@
 			bool get_boolean( const std::string& element, bool defval = false );
 
-			template< uint32 SIZE, typename T >
-			flags< SIZE, T > get_flags( const std::string& element )
-			{
-				flags< SIZE, T > result;
-				get_raw_flags( element, result.data(), result.size() );
-				return result;
-			}
-
-			template< uint32 SIZE, typename T >
-			void load_flags( const std::string& element, flags< SIZE, T >& flags )
-			{
-				get_raw_flags( element, flags.data(), flags.size() );
-			}
-
-		private:
-			void get_raw_flags( const std::string& element, uint8* data, uint32 count );
-
+		private:
 			int m_level;
 		};
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()
 {
