# HG changeset patch # User Matthew Wild # Date 1290194496 0 # Node ID beb0bb936acaab6a50b628284d3abe5d361253da # Parent 94c0441b7321e6a1a2331e1761e857ee6596992c Give LValue an equals() method, returns true/false if the value == the first argument (checks metamethod) diff -r 94c0441b7321 -r beb0bb936aca lvm.js --- 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; } };