diff --git a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h index e3778d733..3df11ab1b 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h +++ b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h @@ -232,6 +232,13 @@ public: Type type() const { return cbindgen_private::sixtyfps_interpreter_value_type(&inner); } + friend bool operator==(const Value &a, const Value &b) { + return cbindgen_private::sixtyfps_interpreter_value_eq(&a.inner, &b.inner); + } + friend bool operator!=(const Value &a, const Value &b) { + return !cbindgen_private::sixtyfps_interpreter_value_eq(&a.inner, &b.inner); + } + private: using ValueOpaque = sixtyfps::cbindgen_private::ValueOpaque; ValueOpaque inner; diff --git a/api/sixtyfps-cpp/tests/tests.cpp b/api/sixtyfps-cpp/tests/tests.cpp index b8eb39dce..18f125657 100644 --- a/api/sixtyfps-cpp/tests/tests.cpp +++ b/api/sixtyfps-cpp/tests/tests.cpp @@ -155,6 +155,29 @@ SCENARIO("Value API") } REQUIRE(destroyed); } + + + SECTION("Compare Values") + { + Value str1{sixtyfps::SharedString("Hello1")}; + Value str2{sixtyfps::SharedString("Hello2")}; + Value fl1{10.}; + Value fl2{12.}; + + REQUIRE(str1 == str1); + REQUIRE(str1 != str2); + REQUIRE(str1 != fl2); + REQUIRE(fl1 == fl1); + REQUIRE(fl1 != fl2); + REQUIRE(Value() == Value()); + REQUIRE(Value() != str1); + REQUIRE(str1 == sixtyfps::SharedString("Hello1")); + REQUIRE(str1 != sixtyfps::SharedString("Hello2")); + REQUIRE(sixtyfps::SharedString("Hello2") == str2); + REQUIRE(fl1 != sixtyfps::SharedString("Hello2")); + REQUIRE(fl2 == 12.); + } + } SCENARIO("Struct API") diff --git a/sixtyfps_runtime/interpreter/api.rs b/sixtyfps_runtime/interpreter/api.rs index 00b3be450..45b7d6650 100644 --- a/sixtyfps_runtime/interpreter/api.rs +++ b/sixtyfps_runtime/interpreter/api.rs @@ -783,6 +783,11 @@ pub(crate) mod ffi { drop(std::ptr::read(val as *mut Value)) } + #[no_mangle] + pub extern "C" fn sixtyfps_interpreter_value_eq(a: &ValueOpaque, b: &ValueOpaque) -> bool { + a.as_value() == b.as_value() + } + /// Construct a new Value in the given memory location as string #[no_mangle] pub unsafe extern "C" fn sixtyfps_interpreter_value_new_string(