我有闭源 C++ 库,它提供的头文件代码相当于:
class CSomething
{
public:
void getParams( unsigned char & u8OutParamOne,
unsigned char & u8OutParamTwo ) const;
private:
unsigned char u8OutParamOne_,
unsigned char u8OutParamTwo_,
};
我试图将它暴露给 Python,我的包装代码是这样的:
BOOST_PYTHON_MODULE(MySomething)
{
class_<CSomething>("CSomething", init<>())
.def("getParams", &CSomething::getParams,(args("one", "two")))
}
现在我正在尝试在 Python 中使用它,但失败了:
one, two = 0, 0
CSomething.getParams(one, two)
结果是:
ArgumentError: Python argument types in
CSomething.getParams(CSomething, int, int)
did not match C++ signature:
getParams(CSomething {lvalue}, unsigned char {lvalue} one, unsigned char {lvalue} two)
我需要在 Boost.Python 包装器代码或 Python 代码中进行哪些更改才能使其正常工作?如何添加一些 Boost.Python 魔法来自动PyInt
转换unsigned char
,反之亦然?