Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 185)
+++ trunk/src/lua/lua_state.cc	(revision 187)
@@ -303,19 +303,25 @@
 }
 
+lua::reference lua::state::register_object( object * o, const char* lua_name )
+{
+	if ( o == nullptr ) return ref_none;
+	stack_guard guard( this );
+	lua_getglobal( L, lua_name );
+	if ( lua_isnil( L, -1 ) )
+	{
+		NV_THROW( runtime_error, std::string( lua_name ) + " type not registered!" );
+	}
+	deep_pointer_copy( -1, o );
+	return luaL_ref( L, LUA_REGISTRYINDEX );
+}
+
 lua::reference lua::state::register_object( object * o )
 {
-	if (!o) return ref_none;
+	if ( o == nullptr ) return ref_none;
 	type_database *db = o->get_root()->get_type_database();
-	if (!db) return ref_none;
-	type_entry* t = db->get_type(typeid(o));
-	if (!t) return ref_none;
-	stack_guard guard( this );
-	lua_getglobal( L, t->name.c_str() );
-	if ( lua_isnil( L, -1 ) )
-	{
-		NV_THROW( runtime_error, std::string( t->name ) + " type not registered!" );
-	}
-	deep_pointer_copy( -1, o );
-    return luaL_ref( L, LUA_REGISTRYINDEX );
+	if ( db == nullptr ) return ref_none;
+	type_entry* t = db->get_type(typeid(*o));
+	if ( t == nullptr ) return ref_none;
+	return register_object( o, t->name.c_str() );
 }
 
@@ -403,5 +409,4 @@
 	if ( !p.resolve( L, global ) )
 	{
-		lua_pop( L, 1 );
 		NV_LOG( LOG_ERROR, "Lua error : not a valid path - " + p.to_string() );
 		return false;
@@ -416,2 +421,3 @@
 	return true;
 }
+
