Index: trunk/src/lua/lua_object.cc
===================================================================
--- trunk/src/lua/lua_object.cc	(revision 262)
+++ trunk/src/lua/lua_object.cc	(revision 262)
@@ -0,0 +1,21 @@
+// 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_object.hh"
+
+#include "nv/lua/lua_raw.hh"
+
+void nv::lua::detail::push_object  ( lua_State *L, object* o )
+{
+	if ( o == nullptr )
+	{
+		lua_pushnil( L );
+	}
+	else
+	{
+		lua_rawgeti( L, LUA_REGISTRYINDEX, o->get_lua_index() );
+	}
+}
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 261)
+++ trunk/src/lua/lua_state.cc	(revision 262)
@@ -11,6 +11,4 @@
 #include "nv/logging.hh"
 #include "nv/string.hh"
-#include "nv/root.hh"
-#include "nv/types.hh"
 
 using namespace nv;
@@ -205,10 +203,10 @@
 // state
 
-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 )
+lua::state::state( lua_State* state ) : state_wrapper( state, false )
+{
+
+}
+
+lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true )
 {
 	load_lua_library();
@@ -222,5 +220,4 @@
 	if ( load_libs )
 	{
-		m_type_database = new type_database();
 		stack_guard guard( this );
 		static const luaL_Reg lualibs[] =
@@ -331,5 +328,5 @@
 }
 
-lua::reference lua::state::register_object( object * o, const char* lua_name )
+lua::reference lua::state::register_object( void* o, const char* lua_name )
 {
 	if ( o == nullptr ) return ref_none;
@@ -344,5 +341,5 @@
 }
 
-lua::reference lua::state::register_proto( object * o, const char* storage )
+lua::reference lua::state::register_proto( const char* id, const char* storage )
 {
 	stack_guard guard( this );
@@ -352,18 +349,10 @@
 		NV_THROW( runtime_error, std::string( storage ) + " storage not registered!" );
 	}
-	lua_getfield( m_state, -1, o->get_id().c_str() );
+	lua_getfield( m_state, -1, id );
 	if ( lua_isnil( m_state, -1 ) )
 	{
-		NV_THROW( runtime_error, std::string( o->get_id() ) + " not found in " + std::string( storage ) + " storage!" );
+		NV_THROW( runtime_error, std::string( id ) + " not found in " + std::string( storage ) + " storage!" );
 	}
 	return luaL_ref( m_state, LUA_REGISTRYINDEX );
-}
-
-lua::reference lua::state::register_object( object * 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() );
 }
 
@@ -380,19 +369,14 @@
 }
 
-void lua::state::unregister_object( object * o )
-{
-	if (!o) return;
-	unregister_object( o->get_lua_index() );
-}
-
-void lua::state::unregister_object( int index )
-{
+void lua::state::unregister_object( reference object_index )
+{
+	if ( object_index == ref_nil ) return;
 	stack_guard guard( this );
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, index );
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
 	lua_pushstring( m_state, "__ptr" );
 	lua_pushboolean( m_state, false );
 	lua_rawset( m_state, -3 );
 	lua_pop( m_state, 1 );
-	luaL_unref( m_state, LUA_REGISTRYINDEX, index );
+	luaL_unref( m_state, LUA_REGISTRYINDEX, object_index );
 }
 
@@ -435,27 +419,9 @@
 }
 
-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 )
-	{
-		lua_pushinteger( m_state, entry.value );
-		if ( prefix.empty() )
-		{
-			lua_setglobal( m_state, entry.name.c_str() );
-		}
-		else
-		{
-			lua_setglobal( m_state, ( prefix + entry.name ).c_str() );
-		}
-	}
-}
-
-void nv::lua::state::store_metadata( object* o, const std::string& metaname, void* pointer )
-{
-	if (!o) return;
+void nv::lua::state::store_metadata( reference object_index, const std::string& metaname, void* pointer )
+{
+	if ( object_index == ref_nil ) return;
 	stack_guard guard( this );
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
 	lua_pushstring( m_state, metaname.c_str() );
 	lua_pushlightuserdata( m_state, pointer );
@@ -464,10 +430,8 @@
 }
 
-nv::lua::state::~state()
-{
-	if (m_type_database != nullptr )
-	{
-		delete m_type_database;
-	}
-}
-
+void nv::lua::state::register_enum( const char* name, int value )
+{
+	lua_pushinteger( m_state, value );
+	lua_setglobal( m_state, name );
+}
+
Index: trunk/src/lua/lua_values.cc
===================================================================
--- trunk/src/lua/lua_values.cc	(revision 261)
+++ trunk/src/lua/lua_values.cc	(revision 262)
@@ -8,5 +8,4 @@
 
 #include "nv/lua/lua_raw.hh"
-#include "nv/object.hh"
 
 using nv::lua::linteger;
@@ -71,16 +70,4 @@
 }
 
-void nv::lua::detail::push_object  ( lua_State *L, object* o )
-{
-	if ( o == nullptr )
-	{
-		lua_pushnil( L );
-	}
-	else
-	{
-		lua_rawgeti( L, LUA_REGISTRYINDEX, o->get_lua_index() );
-	}
-}
-
 void nv::lua::detail::push_pointer ( lua_State *L, void* p )
 {
@@ -118,7 +105,12 @@
 }
 
-nv::object* nv::lua::detail::to_object  ( lua_State *L, int index )
+void*       nv::lua::detail::to_pointer ( lua_State *L, int index )
 {
-	object* o = nullptr;
+	return lua_touserdata( L, index );
+}
+
+void* nv::lua::detail::to_ref_object  ( lua_State *L, int index )
+{
+	void* o = nullptr;
 	if ( lua_istable( L , index ) )
 	{
@@ -127,14 +119,9 @@
 		if ( lua_isuserdata( L, -1 ) )
 		{
-			o = static_cast<object*>( lua_touserdata( L, -1 ) );
+			o = lua_touserdata( L, -1 );
 		} 
 		lua_pop( L, 1 );
 	}
 	return o;
-}
-
-void*       nv::lua::detail::to_pointer ( lua_State *L, int index )
-{
-	return lua_touserdata( L, index );
 }
 
@@ -169,7 +156,12 @@
 }
 
-nv::object* nv::lua::detail::to_object  ( lua_State *L, int index, nv::object* def )
+void*       nv::lua::detail::to_pointer ( lua_State *L, int index, void* def )
 {
-	object* o = def;
+	return ( lua_type( L, index ) == LUA_TUSERDATA ? lua_touserdata( L, index ) : def );
+}
+
+void* nv::lua::detail::to_ref_object( lua_State *L, int index, void* def )
+{
+	void* o = def;
 	if ( lua_istable( L , index ) )
 	{
@@ -178,5 +170,5 @@
 		if ( lua_isuserdata( L, -1 ) )
 		{
-			o = static_cast<object*>( lua_touserdata( L, -1 ) );
+			o = lua_touserdata( L, -1 );
 		}
 		lua_pop( L, 1 );
@@ -184,7 +176,2 @@
 	return o;
 }
-
-void*       nv::lua::detail::to_pointer ( lua_State *L, int index, void* def )
-{
-	return ( lua_type( L, index ) == LUA_TUSERDATA ? lua_touserdata( L, index ) : def );
-}
Index: trunk/src/root.cc
===================================================================
--- trunk/src/root.cc	(revision 261)
+++ trunk/src/root.cc	(revision 262)
@@ -24,5 +24,5 @@
 	if ( m_lua_state && o->m_lua_index != lua::ref_none )
 	{
-		m_lua_state->unregister_object( o );
+		m_lua_state->unregister_object( o->m_lua_index );
 	}
 	if ( m_uid_store && o->m_uid != 0 )
@@ -51,5 +51,5 @@
 		if ( storage != nullptr )
 		{
-			o->m_lua_proto_index = m_lua_state->register_proto( o, storage );
+			o->m_lua_proto_index = m_lua_state->register_proto( o->get_id().c_str(), storage );
 		}
 	}
