Index: trunk/src/lua/lua_map_area.cc
===================================================================
--- trunk/src/lua/lua_map_area.cc	(revision 263)
+++ trunk/src/lua/lua_map_area.cc	(revision 265)
@@ -233,7 +233,7 @@
 }
 
-void nv::lua::register_map_area_instance( lua_State* L, int object_index, map_area* area )
-{
-	lua_rawgeti( L, LUA_REGISTRYINDEX, object_index );
+void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area )
+{
+	lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() );
 	lua_pushstring( L, "__map_area_ptr" );
 	lua_pushlightuserdata( L, (map_area*)area );
Index: trunk/src/lua/lua_object.cc
===================================================================
--- trunk/src/lua/lua_object.cc	(revision 263)
+++ 	(revision )
@@ -1,21 +1,0 @@
-// 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 263)
+++ trunk/src/lua/lua_state.cc	(revision 265)
@@ -328,7 +328,7 @@
 }
 
-lua::reference lua::state::register_object( void* o, const char* lua_name )
-{
-	if ( o == nullptr ) return ref_none;
+lua::ref lua::state::register_object( void* o, const char* lua_name )
+{
+	if ( o == nullptr ) return lua::ref( lua::ref::none );
 	stack_guard guard( this );
 	lua_getglobal( m_state, lua_name );
@@ -338,8 +338,8 @@
 	}
 	deep_pointer_copy( -1, o );
-	return luaL_ref( m_state, LUA_REGISTRYINDEX );
-}
-
-lua::reference lua::state::register_proto( const char* id, const char* storage )
+	return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) );
+}
+
+lua::ref lua::state::register_proto( const char* id, const char* storage )
 {
 	stack_guard guard( this );
@@ -354,5 +354,5 @@
 		NV_THROW( runtime_error, std::string( id ) + " not found in " + std::string( storage ) + " storage!" );
 	}
-	return luaL_ref( m_state, LUA_REGISTRYINDEX );
+	return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) );
 }
 
@@ -369,14 +369,14 @@
 }
 
-void lua::state::unregister_object( reference object_index )
-{
-	if ( object_index == ref_nil ) return;
+void lua::state::unregister_object( ref object_index )
+{
+	if ( !object_index.is_valid() ) return;
 	stack_guard guard( this );
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() );
 	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, object_index );
+	luaL_unref( m_state, LUA_REGISTRYINDEX, object_index.get() );
 }
 
@@ -419,8 +419,8 @@
 }
 
-void nv::lua::state::store_metadata( reference object_index, const std::string& metaname, void* pointer )
-{
-	if ( object_index == ref_nil ) return;
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index );
+void nv::lua::state::store_metadata( ref object_index, const std::string& metaname, void* pointer )
+{
+	if ( !object_index.is_valid() ) return;
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() );
 	lua_pushstring( m_state, metaname.c_str() );
 	lua_pushlightuserdata( m_state, pointer );
Index: trunk/src/lua/lua_values.cc
===================================================================
--- trunk/src/lua/lua_values.cc	(revision 263)
+++ trunk/src/lua/lua_values.cc	(revision 265)
@@ -40,4 +40,9 @@
 }
 
+void nv::lua::detail::push_nil( lua_State *L )
+{
+	lua_pushnil( L );
+}
+
 void nv::lua::detail::push_unsigned( lua_State *L, lunsigned v )
 {
@@ -74,4 +79,10 @@
 	lua_pushlightuserdata( L, p );
 }
+
+void nv::lua::detail::push_ref_object ( lua_State *L, ref object )
+{
+	lua_rawgeti( L, LUA_REGISTRYINDEX, object.get() );
+}
+
 
 lunsigned   nv::lua::detail::to_unsigned( lua_State *L, int index )
