-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
Description
It seems to exist an issue with functions.
Two functions:
- concat > a simple concatination of strings (2 args)
- dump_function > dumps the argument (1 arg)
If dump_function is called as first argument, it gets the second argument for the concat.
Will take a look myself too.
nlohmann::json data;
auto array = nlohmann::json::array();
for(int i=0; i<2; i++){
nlohmann::json data_key;
data_key["a_key"] = std::to_string(i);
array.push_back(data_key);
}
data["val"] = array;
data["val_null"] = nlohmann::json::array();
inja::Environment env;
env.add_callback("concat", 2, [](inja::Arguments& args) {
std::stringstream result;
for(ulong i=0;i<args.size();i++)
{
result << args.at(i)->get<std::string>();
}
return result.str();
});
env.add_callback("dump_function ", 1, [](inja::Arguments& args) {
std::cout << "\tDUMP: " << (*args.at(0)).dump() << std::endl;
std::stringstream result;
result << "(";
result << (*args.at(0)).dump();
result << ")";
return result.str();
});
std::cout << env.render("{{ concat(\"A\", dump_function (val)) }} ", data) << std::endl;
std::cout << env.render("{{ concat(dump_function (val), \"B\") }} ", data) << std::endl;
std::cout << env.render("{{ concat(\"A\", dump_function (val_null)) }} ", data) << std::endl;
std::cout << env.render("{{ concat(dump_function (val_null), \"B\") }} ", data) << std::endl;
V2.2.0
DUMP: [{"a_key":"0"},{"a_key":"1"}]
A([{"a_key":"0"},{"a_key":"1"}])
DUMP: [{"a_key":"0"},{"a_key":"1"}]
([{"a_key":"0"},{"a_key":"1"}])B
DUMP: []
A([])
DUMP: []
([])B
V3.0 (master)
DUMP: [{"a_key":"0"},{"a_key":"1"}]
A([{"a_key":"0"},{"a_key":"1"}])
DUMP: "B"
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.302] type must be string, but is array
Metadata
Metadata
Assignees
Labels
No labels