Explorar el Código

Fix for equality operator between boolean and integer/float to behave like C/C++ Javascript

mingodad hace 8 años
padre
commit
508a357a46
Se han modificado 2 ficheros con 12 adiciones y 2 borrados
  1. 11 1
      SquiLu/squirrel/sqvm.cpp
  2. 1 1
      SquiLu/squirrel/sqvm.h

+ 11 - 1
SquiLu/squirrel/sqvm.cpp

@@ -724,6 +724,16 @@ bool SQVM::IsEqual(const SQObjectPtr &o1,const SQObjectPtr &o2)
 	else if(sq_isnumeric(o1) && sq_isnumeric(o2)) {
 	else if(sq_isnumeric(o1) && sq_isnumeric(o2)) {
 		res = (tofloat(o1) == tofloat(o2));
 		res = (tofloat(o1) == tofloat(o2));
 	}
 	}
+	else if(sq_type(o1) == OT_BOOL) {
+        if(sq_type(o2) & SQOBJECT_CANBEFALSE) {
+            res = _integer(o1) == (IsFalse(o2) ? 0 : 1);
+        }
+	}
+	else if(sq_type(o2) == OT_BOOL) {
+        if(sq_type(o1) & SQOBJECT_CANBEFALSE) {
+            res = _integer(o2) == (IsFalse(o1) ? 0 : 1);
+        }
+	}
 	return res;
 	return res;
 }
 }
 
 
@@ -736,7 +746,7 @@ bool SQVM::IsEqualIdentity(const SQObjectPtr &o1,const SQObjectPtr &o2)
 	return res;
 	return res;
 }
 }
 
 
-bool SQVM::IsFalse(SQObjectPtr &o)
+bool SQVM::IsFalse(const SQObjectPtr &o)
 {
 {
 	if(((sq_type(o) & SQOBJECT_CANBEFALSE)
 	if(((sq_type(o) & SQOBJECT_CANBEFALSE)
 		&& ( ((sq_type(o) == OT_FLOAT) && (_float(o) == SQFloat(0.0))) ))
 		&& ( ((sq_type(o) == OT_FLOAT) && (_float(o) == SQFloat(0.0))) ))

+ 1 - 1
SquiLu/squirrel/sqvm.h

@@ -147,7 +147,7 @@ public:
 	void ReplaceAbs(SQInteger n);
 	void ReplaceAbs(SQInteger n);
 	void Insert(SQInteger n);
 	void Insert(SQInteger n);
 
 
-	static bool IsFalse(SQObjectPtr &o);
+	static bool IsFalse(const SQObjectPtr &o);
 
 
 	void Pop();
 	void Pop();
 	void Pop(SQInteger n);
 	void Pop(SQInteger n);