Browse Source

Add __eq metamethod to all objects (checks to see if the Proxy data they represent are equal)

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
d35dbaa28b
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/common/runtime.cpp

+ 12 - 0
src/common/runtime.cpp

@@ -74,6 +74,14 @@ namespace love
 		luax_pushboolean(L, p->flags[t]);
 		return 1;
 	}
+	
+	static int w__eq(lua_State * L)
+	{
+		Proxy * p1 = (Proxy *)lua_touserdata(L, 1);
+		Proxy * p2 = (Proxy *)lua_touserdata(L, 2);
+		luax_pushboolean(L, p1->data == p2->data);
+		return 1;
+	}
 
 	Reference * luax_refif(lua_State * L, int type)
 	{
@@ -197,6 +205,10 @@ namespace love
 		// setup gc
 		lua_pushcfunction(L, w__gc);
 		lua_setfield(L, -2, "__gc");
+		
+		// Add equality
+		lua_pushcfunction(L, w__eq);
+		lua_setfield(L, -2, "__eq");
 
 		// Add tostring function.
 		lua_pushstring(L, tname);