I'm now looking at some codes from the CARLA simulator (http://carla.org/).
It exposes many C++ classes and member functions to python using boost python. But I cannot understand a syntax from lines below..
void export_blueprint() {
using namespace boost::python;
namespace cc = carla::client;
namespace crpc = carla::rpc;
...
class_<cc::ActorBlueprint>("ActorBlueprint", no_init)
.add_property("id", +[](const cc::ActorBlueprint &self) -> std::string {
return self.GetId();
})
.add_property("tags", &cc::ActorBlueprint::GetTags)
.def("contains_tag", &cc::ActorBlueprint::ContainsTag)
.def("match_tags", &cc::ActorBlueprint::MatchTags)
.def("contains_attribute", &cc::ActorBlueprint::ContainsAttribute)
.def("get_attribute", +[](const cc::ActorBlueprint &self, const std::string &id) -> cc::ActorAttribute {
return self.GetAttribute(id);
}) // <=== THESE LINES
.def("set_attribute", &cc::ActorBlueprint::SetAttribute)
.def("__len__", &cc::ActorBlueprint::size)
.def("__iter__", range(&cc::ActorBlueprint::begin, &cc::ActorBlueprint::end))
.def(self_ns::str(self_ns::self))
;
}
What does the code below
.def("get_attribute", +[](const cc::ActorBlueprint &self,
const std::string &id) -> cc::ActorAttribute {
return self.GetAttribute(id);
})
mean? It looks like the python class ActorBlueprint 's function get_attribute function is being newly(overriding) defined with new arguments passed from the python interface. I'm almost sure but is there any document about this syntax? I couldn't find one in https://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/tutorial/index.html.