mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 01:06:54 +08:00
Merge 69476967aeaa245c452a3b3b92b9ba3c571bb958 into 2eb3279c391854c7a005b82ad121802e88b7c171
This commit is contained in:
commit
655c342123
@ -534,6 +534,24 @@ namespace chaiscript {
|
|||||||
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(
|
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(
|
||||||
user_type<std::map<std::string, Boxed_Value>>(), user_type<To>(), func);
|
user_type<std::map<std::string, Boxed_Value>>(), user_type<To>(), func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Left, typename Right>
|
||||||
|
Type_Conversion pair_conversion() {
|
||||||
|
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
||||||
|
const std::pair<Boxed_Value, Boxed_Value> &from_pair
|
||||||
|
= detail::Cast_Helper<const std::pair<Boxed_Value, Boxed_Value> &>::cast(t_bv, nullptr);
|
||||||
|
|
||||||
|
auto pair = std::make_pair(
|
||||||
|
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
||||||
|
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr)
|
||||||
|
);
|
||||||
|
|
||||||
|
return Boxed_Value(std::move(pair));
|
||||||
|
};
|
||||||
|
|
||||||
|
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(
|
||||||
|
user_type<std::pair<Boxed_Value, Boxed_Value>>(), user_type<std::pair<Left, Right>>(), func);
|
||||||
|
}
|
||||||
} // namespace chaiscript
|
} // namespace chaiscript
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -866,6 +866,27 @@ TEST_CASE("Map conversions") {
|
|||||||
CHECK(c == 42);
|
CHECK(c == 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Pair conversions") {
|
||||||
|
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||||
|
chai.add(chaiscript::pair_conversion<std::string, std::string>());
|
||||||
|
chai.add(chaiscript::pair_conversion<int, double>());
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto p = chai.eval<std::pair<std::string, std::string>>(R"cs(
|
||||||
|
Pair("chai", "script");
|
||||||
|
)cs");
|
||||||
|
CHECK(p.first == std::string{ "chai" });
|
||||||
|
CHECK(p.second == "script");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const auto p = chai.eval<std::pair<int, double>>(R"cs(
|
||||||
|
Pair(5, 3.14);
|
||||||
|
)cs");
|
||||||
|
CHECK(p.first == 5);
|
||||||
|
CHECK(p.second == Approx(3.14));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse floats with non-posix locale") {
|
TEST_CASE("Parse floats with non-posix locale") {
|
||||||
#ifdef CHAISCRIPT_MSVC
|
#ifdef CHAISCRIPT_MSVC
|
||||||
std::setlocale(LC_ALL, "en-ZA");
|
std::setlocale(LC_ALL, "en-ZA");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user