Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 228)
+++ trunk/src/lua/lua_state.cc	(revision 256)
@@ -383,12 +383,18 @@
 {
 	if (!o) return;
+	unregister_object( o->get_lua_index() );
+}
+
+void lua::state::unregister_object( int index )
+{
 	stack_guard guard( this );
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, 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, o->get_lua_index() );
-}
+	luaL_unref( m_state, LUA_REGISTRYINDEX, index );
+}
+
 
 void lua::state::deep_pointer_copy( int index, void* obj )
