我现在正在查看来自 CARLA 模拟器 ( http://carla.org/ ) 的一些代码。
它使用 boost python 向 python 公开了许多 C++ 类和成员函数。但我无法理解下面几行的语法。
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))
;
}
下面的代码是什么
.def("get_attribute", +[](const cc::ActorBlueprint &self,
const std::string &id) -> cc::ActorAttribute {
return self.GetAttribute(id);
})
意思是?看起来 python 类 ActorBlueprint 的函数 get_attribute 函数正在被新(覆盖)定义为从 python 接口传递的新参数。我几乎可以肯定,但是否有任何关于此语法的文档?我在https://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/tutorial/index.html 中找不到一个。
米琪卡哇伊
相关分类