[core] For string-valued properties, do coercion rather than assertion

This commit is contained in:
John Firebaugh
2018-09-13 15:03:19 -07:00
committed by Chris Loer
parent 89b075f592
commit 2e93a9ddcf
9 changed files with 89 additions and 51 deletions

View File

@@ -309,19 +309,6 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
define("typeof", [](const Value& v) -> Result<std::string> { return toString(typeOf(v)); });
define("to-string", [](const Value& value) -> Result<std::string> {
return toString(value);
});
define("to-boolean", [](const Value& v) -> Result<bool> {
return v.match(
[&] (double f) { return static_cast<bool>(f); },
[&] (const std::string& s) { return s.length() > 0; },
[&] (bool b) { return b; },
[&] (const NullValue&) { return false; },
[&] (const auto&) { return true; }
);
});
define("to-rgba", [](const Color& color) -> Result<std::array<double, 4>> {
return color.toArray();
});