我正在尝试使用具有函数成员的类公开c++库,这些类通过pybind11将双指针参数(用于初始化)接收到python。
例如:
class IInitializer{
virtual bool CreateTexture(ITexture **out_pTex, UINT Width, UINT Height) = 0;
}我知道pybind11不支持双指针参数的开箱即用.
在python方面,我希望以长号或不透明指针的形式接收out_pTex。我不需要对python端的这个指针做任何事情,只要将它作为句柄传递给其他c++函数即可。
我试图创建这样的定制类型的连铸机:
template <> struct type_caster<ITexture*> : public type_caster_base<ITexture*>
{
using base = type_caster_base<ITexture*>;
public:
PYBIND11_TYPE_CASTER(ITexture*, const_name("ITexture*"));
bool load(handle src, bool) {
value = reinterpret_cast<ITexture*>(PyLong_AsVoidPtr(src.ptr()));
return true;
}
static handle cast(ITexture* src, return_value_policy, handle) {
return PyLong_FromVoidPtr((void*)src);
}
};但是我不断地收到编译错误,比如:
no known conversion for argument 1 from ‘pybind11::detail::type_caster_base<ITexture>::cast_op_type<ITexture**&&> {aka ITexture*}’ to ‘ITexture**’有人建议如何将指向某个类(作为不透明的或长的数字)的双指针公开到python?
发布于 2022-04-18 19:04:26
我会把胶水代码写成lambda:
IInitializerWrap.def("CreateTexture", [](const IInitializer& self, UINT Width, UINT Height) {
ITexture* rv;
self.CreateTexture(&rv, Width, Height);
return rv; // Or reinterpret_cast if you prefer to.
});https://stackoverflow.com/questions/71912177
复制相似问题