SWIG passing argument to python callback function

后端 未结 1 925
旧巷少年郎
旧巷少年郎 2021-01-03 02:26

So I\'m almost done. Now I have working code which calls python callback function.

Only thing I need now is how to pass argument to the python callback function.

相关标签:
1条回答
  • 2021-01-03 03:08

    The arguments to the callback are the second argument to PyEval_CallObject(). Right now you're building an empty tuple, which means "no arguments". So, change that. Where you now do:

    arglist = Py_BuildValue("()");  /* No arguments needed */
    

    you instead pass Py_BuildValue whatever arguments you want the Python function to receive. For example, if you want to pass the callback an integer, a string and a Python object you got from somewhere, you would do:

    arglist = Py_BuildValue("(isO)", the_int, the_str, the_pyobject);
    
    0 讨论(0)
提交回复
热议问题