Add map conversions

closes #57
This commit is contained in:
Jason Turner
2016-01-29 20:41:12 -07:00
parent 7f4ef8d8fd
commit bde2a45384
3 changed files with 50 additions and 0 deletions

View File

@@ -872,6 +872,7 @@ struct Returned_Converted_Config
};
TEST_CASE("Return of converted type from script")
{
chaiscript::ChaiScript chai;
@@ -914,3 +915,27 @@ TEST_CASE("Return of converted type from script")
}
int get_value_a(const std::map<std::string, int> &t_m)
{
return t_m.at("a");
}
TEST_CASE("Map conversions")
{
chaiscript::ChaiScript chai;
chai.add(chaiscript::map_conversion<std::map<std::string, int>>());
chai.add(chaiscript::fun(&get_value_a), "get_value_a");
const auto c = chai.eval<int>(R"(
var m = ["a": 42];
get_value_a(m);
)");
CHECK(c == 42);
}