2
raw_function
을 사용하여 클래스 메서드를 노출하려고합니다. 같은 뭔가 : 지금부스트 파이썬 raw_function 메서드
namespace py = boost::python;
class MyObject {
public:
py::object foo(py::tuple args, py::dict kwargs) {
// whatever
}
};
, 나는 밖으로 self
을 당겨하는 정적 기능을 래핑하는 raw_function
을 사용할 수 있습니다, 그래서 뭔가 같은 : 작동하지만, 꽤 장황
static py::object MyObject_foo(py::tuple args, py::dict kwargs) {
MyObject& self = py::extract<MyObject&>(args[0]);
// the docs allege that I can do args.slice(1), but that doesn't
// compile on boost 1.55 at least, with no matching function
// call to 'boost::python::tuple::slice(int) const
self.foo(py::extract<py::tuple>(args.slice(1, py::len(args))),
kwargs);
}
py::class_<MyClass>("MyClass")
.def("foo", py::raw_function(&MyObject_foo, 1));
. 나는 실제로 랩핑이 필요하고 각각의 중간 단계를 거치지 않는 것을 선호하는 몇몇 원시 함수를 가지고있다. MyObject::foo
을 줄이는 더 짧은 방법이 있습니까?
내 문제가 해결되었지만 여전히 "클래스 내"입니다. 감사! – wgodoy