我正在为API创建一个C ++到python接口,我不允许修改C ++的重要部分来获取我的接口。
我选择使用Boost :: Python作为从C ++到python的桥梁。我已经定义了BOOST_PYTHON_MODULE的以下部分:
开始我的C ++部分:
describe('With Snapshot Testing', () => {
it('About shows "About"', () => {
const component = renderer.create(<About />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
})
从我的翻译中,我对这个界面的使用如下:
using namespace boost::python;
BOOST_PYTHON_MODULE(sandman_lib) {
class_<manblock::ManDriver>("ManDriver", init< ... >())
scope sandprogression = class_<SandProgression>("sandprogression");
def("api_create_sand_c_side_from_cfg_file", api_create_sand_c_side_from_cfg_file);
}
当然,在“sandprogression”范围内,我们有上面尝试使用的这个函数的原型,它被定义为:
>>> import sandman_lib
>>> SAND = sandman_lib.sand_progression()
>>> SAND
<sandman_lib.sandprogression object at 0x7ffff7eaa998>
>>> SAND.api_create_sand_c_side_from_cfg_file("path_to_my_config_file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
sandprogression.api_create_sand_c_side_from_cfg_file(sandprogression, str)
did not match C++ signature:
api_create_sand_c_side_from_cfg_file(char const*)
我会假设某些类型可以在C ++和Python之间自动转换,但显然情况并非如此。我一直在倾注提升文档,试图理解如何简单地设置映射,但我似乎无法理解它是如何完成的。
答案 0 :(得分:0)
sandman_lib.sandprogression.api_blah("path")
代替sandman_lib.sandprogression().api_blah("path")
。看看example on boost.org。