Index: trunk/src/lua/lua_area.cc
===================================================================
--- trunk/src/lua/lua_area.cc	(revision 206)
+++ trunk/src/lua/lua_area.cc	(revision 207)
@@ -11,35 +11,24 @@
 #include "nv/random.hh"
 
-static const char* NLUA_AREA_METATABLE = "area";
-
-bool nlua_is_area( lua_State* L, int index )
-{
-	return luaL_testudata( L, index, NLUA_AREA_METATABLE ) != 0;
-}
-
-nv::rectangle nlua_to_area( lua_State* L, int index )
-{
-	return *(nv::rectangle*)luaL_checkudata( L, index, NLUA_AREA_METATABLE );
-}
-
-nv::rectangle* nlua_to_parea( lua_State* L, int index )
-{
-	return (nv::rectangle*)luaL_checkudata( L, index, NLUA_AREA_METATABLE );
-}
-
-void nlua_push_area( lua_State* L, const nv::rectangle& v )
-{
-	new (lua_newuserdata(L, sizeof(nv::rectangle))) nv::rectangle(v);
-	luaL_setmetatable( L, NLUA_AREA_METATABLE );
-}
+const char* nv::lua::detail::AREA_METATABLE = "area";
+
+using nv::lua::detail::is_coord;
+using nv::lua::detail::to_coord;
+using nv::lua::detail::to_pcoord;
+using nv::lua::detail::push_coord;
+
+using nv::lua::detail::is_area;
+using nv::lua::detail::to_area;
+using nv::lua::detail::to_parea;
+using nv::lua::detail::push_area;
 
 static void nlua_area_construct( lua_State* L, int sidx )
 {
-	if ( nlua_is_coord( L, sidx ) )
-	{
-		if ( nlua_is_coord( L, sidx+1 ) )
+	if ( is_coord( L, sidx ) )
+	{
+		if ( is_coord( L, sidx+1 ) )
 		{
-			nv::rectangle a( nlua_to_coord( L, sidx ), nlua_to_coord( L, sidx+1 ) );
-			nlua_push_area( L, a );
+			nv::rectangle a( to_coord( L, sidx ), to_coord( L, sidx+1 ) );
+			push_area( L, a );
 			return;
 		}
@@ -51,5 +40,5 @@
 		nv::ivec2( lua_tointeger( L, sidx+2 ), lua_tointeger( L, sidx+3 ) )
 		);
-	nlua_push_area( L, a );
+	push_area( L, a );
 }
 
@@ -69,5 +58,5 @@
 static int nlua_area_eq( lua_State* L )
 {
-	lua_pushboolean( L, nlua_to_area( L, 1 ) == nlua_to_area( L, 2 ) );
+	lua_pushboolean( L, to_area( L, 1 ) == to_area( L, 2 ) );
 	return 1;
 }
@@ -75,7 +64,7 @@
 static int nlua_area_get( lua_State* L )
 {
-	nv::rectangle r( nlua_to_area( L, 1 ) );
-	nlua_push_coord( L, r.ul );
-	nlua_push_coord( L, r.lr );
+	nv::rectangle r( to_area( L, 1 ) );
+	push_coord( L, r.ul );
+	push_coord( L, r.lr );
 	return 2;
 }
@@ -83,5 +72,5 @@
 static int nlua_area_clone( lua_State* L )
 {
-	nlua_push_area( L, *nlua_to_parea( L, 1 ) );
+	push_area( L, *to_parea( L, 1 ) );
 	return 1;
 }
@@ -89,14 +78,14 @@
 static int nlua_area_index( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	std::size_t l;
 	const char* index = lua_tolstring( L, 2, &l );
 	if ( l == 1 && index[0] == 'a' )
 	{
-		nlua_push_coord( L, a->ul );
+		push_coord( L, a->ul );
 	}
 	else if ( l == 1 && index[0] == 'b' )
 	{
-		nlua_push_coord( L, a->lr );
+		push_coord( L, a->lr );
 	}
 	else
@@ -111,8 +100,8 @@
 static int nlua_area_newindex( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	std::size_t l;
 	const char* index = lua_tolstring( L, 2, &l );
-	nv::ivec2 value( nlua_to_coord( L, 3 ) );
+	nv::ivec2 value( to_coord( L, 3 ) );
 	if ( l == 1 && index[0] == 'a' )
 	{
@@ -128,6 +117,6 @@
 static int lua_area_coords_closure( lua_State* L )
 {
-	nv::rectangle* a( nlua_to_parea( L, lua_upvalueindex(1) ) );
-	nv::ivec2*     c( nlua_to_pcoord( L, lua_upvalueindex(2) ) );
+	nv::rectangle* a( to_parea( L, lua_upvalueindex(1) ) );
+	nv::ivec2*     c( to_pcoord( L, lua_upvalueindex(2) ) );
 
 	c->x++;
@@ -144,5 +133,5 @@
 	}
 
-	nlua_push_coord( L, *c );
+	push_coord( L, *c );
 	return 1;
 }
@@ -150,8 +139,8 @@
 static int nlua_area_coords( lua_State* L )
 {
-	nv::rectangle* a( nlua_to_parea( L, 1 ) );
+	nv::rectangle* a( to_parea( L, 1 ) );
 	nv::ivec2      c( a->ul );
 	c.x--;
-	nlua_push_coord( L, c );
+	push_coord( L, c );
 	lua_pushcclosure( L, lua_area_coords_closure, 2 );
 	return 1;
@@ -160,6 +149,6 @@
 static int nlua_area_edges_closure( lua_State* L )
 {
-	nv::rectangle* a( nlua_to_parea( L, lua_upvalueindex(1) ) );
-	nv::ivec2*     c( nlua_to_pcoord( L, lua_upvalueindex(2) ) );
+	nv::rectangle* a( to_parea( L, lua_upvalueindex(1) ) );
+	nv::ivec2*     c( to_pcoord( L, lua_upvalueindex(2) ) );
 
 	c->x++;
@@ -178,5 +167,5 @@
 
 
-	nlua_push_coord( L, *c );
+	push_coord( L, *c );
 	return 1;
 }
@@ -184,8 +173,8 @@
 static int nlua_area_edges( lua_State* L )
 {
-	nv::rectangle*   a( nlua_to_parea( L, 1 ) );
+	nv::rectangle*   a( to_parea( L, 1 ) );
 	nv::ivec2 c( a->ul );
 	c.x--;
-	nlua_push_coord( L, c );
+	push_coord( L, c );
 	lua_pushcclosure( L, nlua_area_edges_closure, 2 );
 	return 1;
@@ -203,14 +192,14 @@
 static int nlua_area_corners( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 
 	lua_createtable(L, 4, 0);
-	nlua_push_coord( L, a->ul );
+	push_coord( L, a->ul );
 	lua_rawseti( L, -2, 1 );
-	nlua_push_coord( L, a->ur() );
+	push_coord( L, a->ur() );
 	lua_rawseti( L, -2, 2 );
-	nlua_push_coord( L, a->ll() );
+	push_coord( L, a->ll() );
 	lua_rawseti( L, -2, 3 );
-	nlua_push_coord( L, a->lr );
+	push_coord( L, a->lr );
 	lua_rawseti( L, -2, 4 );
 
@@ -222,5 +211,5 @@
 static int nlua_area_shrink( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	a->shrink( static_cast< int >( lua_tointeger( L, 2 ) ) );
 	return 0;
@@ -229,6 +218,6 @@
 static int nlua_area_shrinked( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
-	nlua_push_area( L, a->shrinked( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
+	nv::rectangle* a = to_parea( L, 1 );
+	push_area( L, a->shrinked( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
 	return 1;
 }
@@ -236,5 +225,5 @@
 static int nlua_area_expand( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	a->expand( static_cast< int >( lua_tointeger( L, 2 ) ) );
 	return 0;
@@ -243,6 +232,6 @@
 static int nlua_area_expanded( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
-	nlua_push_area( L, a->expanded( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
+	nv::rectangle* a = to_parea( L, 1 );
+	push_area( L, a->expanded( static_cast< int >( lua_tointeger( L, 2 ) ) ) );
 	return 1;
 }
@@ -250,6 +239,6 @@
 static int nlua_area_clamp( lua_State* L )
 {
-	nv::rectangle* a1 = nlua_to_parea( L, 1 );
-	nv::rectangle* a2 = nlua_to_parea( L, 2 );
+	nv::rectangle* a1 = to_parea( L, 1 );
+	nv::rectangle* a2 = to_parea( L, 2 );
 	a1->clamp_to( *a2 );
 	return 0;
@@ -258,8 +247,8 @@
 static int nlua_area_clamped( lua_State* L )
 {
-	nv::rectangle  a1 = nlua_to_area( L, 1 );
-	nv::rectangle* a2 = nlua_to_parea( L, 2 );
+	nv::rectangle  a1 = to_area( L, 1 );
+	nv::rectangle* a2 = to_parea( L, 2 );
 	a1.clamp_to( *a2 );
-	nlua_push_area( L, a1 );
+	push_area( L, a1 );
 	return 1;
 }
@@ -267,6 +256,6 @@
 static int nlua_area_clamp_coord( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
-	nv::ivec2*     c = nlua_to_pcoord( L, 2 );
+	nv::rectangle* a = to_parea( L, 1 );
+	nv::ivec2*     c = to_pcoord( L, 2 );
 	*c = glm::clamp( *c, a->ul, a->lr );
 	return 0;
@@ -275,7 +264,7 @@
 static int nlua_area_clamped_coord( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
-	nv::ivec2*     c = nlua_to_pcoord( L, 2 );
-	nlua_push_coord( L, glm::clamp( *c, a->ul, a->lr ) );
+	nv::rectangle* a = to_parea( L, 1 );
+	nv::ivec2*     c = to_pcoord( L, 2 );
+	push_coord( L, glm::clamp( *c, a->ul, a->lr ) );
 	return 0;
 }
@@ -283,5 +272,5 @@
 static int nlua_area_fix( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	if ( a->ul.x > a->lr.x ) a->ul.x = a->lr.x;
 	if ( a->ul.y > a->lr.y ) a->ul.y = a->lr.y;
@@ -291,5 +280,5 @@
 static int nlua_area_proper( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	lua_pushboolean( L, a->ul.x <= a->lr.x && a->ul.y <= a->lr.y );
 	return 1;
@@ -298,6 +287,6 @@
 static int nlua_area_dim( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
-	nlua_push_coord( L, a->ul - a->lr + nv::ivec2(1,1) );
+	nv::rectangle* a = to_parea( L, 1 );
+	push_coord( L, a->ul - a->lr + nv::ivec2(1,1) );
 	return 1;
 }
@@ -305,5 +294,5 @@
 static int nlua_area_size( lua_State* L )
 {
-	nv::rectangle* a = nlua_to_parea( L, 1 );
+	nv::rectangle* a = to_parea( L, 1 );
 	lua_pushinteger( L, a->get_enclosed_area() );
 	return 1;
@@ -312,5 +301,5 @@
 static int nlua_area_contains( lua_State* L )
 {
-	lua_pushboolean( L, nlua_to_parea( L, 1 )->contains( nlua_to_coord( L, 2 ) ) );
+	lua_pushboolean( L, to_parea( L, 1 )->contains( to_coord( L, 2 ) ) );
 	return 1;
 }
@@ -318,6 +307,6 @@
 static int nlua_area_is_edge( lua_State* L )
 {
-	nv::rectangle a = nlua_to_area( L, 1 );
-	nv::ivec2     c = nlua_to_coord( L, 2 );
+	nv::rectangle a = to_area( L, 1 );
+	nv::ivec2     c = to_coord( L, 2 );
 	lua_pushboolean( L, a.contains( c ) && ( c.x == a.ul.x || c.x == a.lr.x || c.y == a.ul.y || c.y == a.lr.y ) );
 	return 1;
@@ -326,8 +315,8 @@
 static int nlua_area_around( lua_State* L )
 {
-	nv::ivec2 c = nlua_to_coord( L, 1 );
+	nv::ivec2 c = to_coord( L, 1 );
 	int amount = static_cast< int >( lua_tointeger( L, 1 ) );
 	nv::ivec2 shift( amount, amount );
-	nlua_push_area( L, nv::rectangle( c - shift, c + shift ) );
+	push_area( L, nv::rectangle( c - shift, c + shift ) );
 	return 1;
 }
@@ -335,5 +324,5 @@
 static int nlua_area_tostring( lua_State* L )
 {
-	nv::rectangle a = nlua_to_area( L, 1 );
+	nv::rectangle a = to_area( L, 1 );
 	std::string s = "(";
 	s += nv::to_string(a.ul.x);
@@ -351,5 +340,5 @@
 static int nlua_area_random_edge_coord( lua_State* L )
 {
-	nv::rectangle area = nlua_to_area( L, 1 );
+	nv::rectangle area = to_area( L, 1 );
 	nv::ivec2 a   = area.ul;
 	nv::ivec2 b   = area.lr;
@@ -368,5 +357,5 @@
 		result = ( roll < ys ) ? nv::ivec2( a.x, a.y + roll + 1 ) : nv::ivec2( b.x, a.y + roll - ys + 1);
 	}
-	nlua_push_coord( L, result );
+	push_coord( L, result );
 	return 1;
 }
@@ -374,5 +363,5 @@
 static int nlua_area_random_inner_edge_coord( lua_State* L )
 {
-	nv::rectangle area = nlua_to_area( L, 1 );
+	nv::rectangle area = to_area( L, 1 );
 	nv::ivec2 a   = area.ul;
 	nv::ivec2 b   = area.lr;
@@ -391,5 +380,5 @@
 		result = ( roll < ys ) ? nv::ivec2( a.x, a.y + roll + 1 ) : nv::ivec2( b.x, a.y + roll - ys + 1);
 	}
-	nlua_push_coord( L, result );
+	push_coord( L, result );
 	return 1;
 }
@@ -397,6 +386,6 @@
 static int nlua_area_random_coord( lua_State* L )
 {
-	nv::rectangle area = nlua_to_area( L, 1 );
-	nlua_push_coord( L, nv::random::get().range( area.ul, area.lr ) );
+	nv::rectangle area = to_area( L, 1 );
+	push_coord( L, nv::random::get().range( area.ul, area.lr ) );
 	return 1;
 }
@@ -404,8 +393,8 @@
 static int nlua_area_random_subarea( lua_State* L )
 {
-	nv::rectangle area  = nlua_to_area( L, 1 );
-	nv::ivec2     dim   = nlua_to_coord( L, 2 );
+	nv::rectangle area  = to_area( L, 1 );
+	nv::ivec2     dim   = to_coord( L, 2 );
 	nv::ivec2     start = nv::random::get().range( area.ul, area.lr - dim );
-	nlua_push_area( L, nv::rectangle( start, start + dim ) );
+	push_area( L, nv::rectangle( start, start + dim ) );
 	return 1;
 }
@@ -466,5 +455,5 @@
 	};
 
-	luaL_newmetatable( L, NLUA_AREA_METATABLE );
+	luaL_newmetatable( L, nv::lua::detail::AREA_METATABLE );
 	nlua_register( L, nlua_area_m, -1 );
 	lua_createtable( L, 0, 0 );
@@ -481,5 +470,5 @@
 }
 
-void nlua_register_area( lua_State* L )
+void nv::lua::register_area( lua_State* L )
 {
 	int stack = lua_gettop( L );
