lvm.js

changeset 80
beb0bb936aca
parent 79
94c0441b7321
child 81
1deed5894ff6
--- a/lvm.js	Fri Nov 19 16:57:32 2010 +0000
+++ b/lvm.js	Fri Nov 19 19:21:36 2010 +0000
@@ -118,6 +118,27 @@
 		}
 		else
 			throw "Attempt to perform arithmetic on a "+this.type+" and "+op2.type;
+	},
+	equals: function (op2)
+	{
+		if(this.type != op2.type)
+			return false;
+		if(this.value == op2.value)
+			return true;
+		var __eq = this.vm.LValue("__eq");
+		if(this.metatable && op2.metatable)
+		{
+			var metamethod1 = this.metatable.index(__eq);
+			var metamethod2 = op2.metatable.index(__eq);
+			if(metamethod1.equals(metamethod2))
+			{
+				var result = metamethod1.call([this, op2]);
+				return (result[0].type != "nil"
+					&& (result[0].type != "boolean" || result[0].value == true)
+				);
+			}
+		}
+		return false;
 	}
 };
 

mercurial