开发者

Embedding Python: How to help the scripter?

I'm using Boost to embed Python in my application. For example, I want to check that the following function rece开发者_如何学Pythonives an integer and a string as the first and second parameters (the function is defined in C++).

someFunction(123, 'words')

If I find that the parameters are incorrect, how can I notify the scripter about which line they need to correct, for example?


If you wrap the function using usual def("someFunction",someFunction,...), caller will get automatically notified about c++ signature which could not be matched with objects passed from python, like this (the method takes one dictionary argument, is called with 3 numbers instead):

>>> 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)

Can you post some code to see what is your problem?


Raise an exception with all the information you want them to know, just like you would in Python. In fact, that answer seems so obvious, it makes me think I'm missing something in your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜