我正在使用 Boost 将 Python 嵌入到我的应用程序中。例如,我想检查以下函数是否接收一个整数和一个字符串作为第一个和第二个参数(该函数是在 C++ 中定义的)。
someFunction(123, 'words')
如果我发现参数不正确,我该如何通知脚本编写者他们需要更正哪一行?
最佳答案
如果您使用通常的 def("someFunction",someFunction,...)
包装函数,调用者将自动收到有关无法匹配的 c++ 签名的通知使用从 python 传递的对象,像这样(该方法采用一个字典参数,而是用 3 个数字调用):
>>> scene.updateAttrs(1,2,3)
ArgumentError: Python argument types in
Serializable.updateAttrs(Scene, int, int, int)
did not match C++ signature:
updateAttrs(Serializable {lvalue}, boost::python::dict)
你能发布一些代码看看你的问题是什么吗?
关于c++ - 嵌入 Python : How to help the scripter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939711/