Index: trunk/src/lua/lua_flags.cc
===================================================================
--- trunk/src/lua/lua_flags.cc	(revision 214)
+++ trunk/src/lua/lua_flags.cc	(revision 215)
@@ -20,8 +20,8 @@
 	// TODO : this can be optimized
 	lua_createtable( L, 0, 0 );
-	for ( uint32 c = 0; c < count; ++c )
+	for ( int c = 0; c < static_cast< int >( count ); ++c )
 	{
-		uint32 idx = c / 8;
-		uint32 pos = c % 8;
+		int idx = c / 8;
+		int pos = c % 8;
 		if ( ( data[ idx ] & ( 1 << static_cast< uint8 >( pos ) ) ) != 0 )
 		{
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 214)
+++ trunk/src/lua/lua_state.cc	(revision 215)
@@ -32,10 +32,10 @@
 }
 
-lua::state::state( lua_State* state ) : state_wrapper( state, false )
-{
-
-}
-
-lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true )
+lua::state::state( lua_State* state ) : state_wrapper( state, false ), m_type_database( nullptr )
+{
+
+}
+
+lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true ), m_type_database( nullptr )
 {
 	load_lua_library();
@@ -49,4 +49,5 @@
 	if ( load_libs )
 	{
+		m_type_database = new type_database();
 		stack_guard guard( this );
 		static const luaL_Reg lualibs[] =
@@ -290,8 +291,6 @@
 lua::reference lua::state::register_object( object * o )
 {
-	if ( o == nullptr ) return ref_none;
-	type_database *db = o->get_root()->get_type_database();
-	if ( db == nullptr ) return ref_none;
-	type_entry* t = db->get_type(typeid(*o));
+	if ( o == nullptr || m_type_database == nullptr ) return ref_none;
+	type_entry* t = m_type_database->get_type(typeid(*o));
 	if ( t == nullptr ) return ref_none;
 	return register_object( o, t->name.c_str() );
@@ -359,7 +358,7 @@
 }
 
-void lua::state::register_enum( type_database* db, const std::string& name, const std::string& prefix /*= std::string() */ )
-{
-	type_entry* et = db->get_type( name );
+void lua::state::register_enum_values( const std::string& name, const std::string& prefix /*= std::string() */ )
+{
+	type_entry* et = m_type_database->get_type( name );
 
 	for ( const auto& entry : et->enum_list )
@@ -388,4 +387,12 @@
 }
 
+nv::lua::state::~state()
+{
+	if (m_type_database != nullptr )
+	{
+		delete m_type_database;
+	}
+}
+
 bool nv::lua::state_wrapper::is_defined( const path& p, bool global )
 {
