开发者

C++ callback with python through SWIG when the function takes non-trivial arguments?

开发者 https://www.devze.com 2023-03-17 00:02 出处:网络
I just read the following section of the \"SWIG and Python\" tutorial: http://www.swig.org/Doc1.1/HTML/Python.html#n11

I just read the following section of the "SWIG and Python" tutorial: http://www.swig.org/Doc1.1/HTML/Python.html#n11

I understand what they do in the example, basically you write a C function that calls python. However, the example provided takes only a double in the argument list, making it rather trivial to buil开发者_StackOverflowd an argument list for python.

I have a C++ callback that has the following signature:

Vector (*CALLBACK)(Simulation*, Vector, Vector, double, void*)

where Vector and Simulation are my own classes, and void* is for clientData holding a PyObject (as used in the example)

I know that SWIG wraps both the Vector and Simulation classes, because I can create them in a python shell. The only problem is, I have no idea how to transform a Vector argument in the callback function to an appropriate PyObject for the python argument list. SWIG obviously has some way to do this when it wraps the class itself, but I don't know how to accomplish it manually in the function.

Any help much appreciated! -Chase


I do not think your question is actually about SWIG; it is purely about Python. At this level, your problem is simply calling in to Python from C, so you need to study "Parsing arguments and building values" in the Python documentation. (Also "Extending and Embedding the Python interpreter".)

0

精彩评论

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