4
這裏是我的C++代碼:調用C++中的Python函數與痛飲
void callMethod(void (*someMethod)()) {
(*someMethod)();
}
我痛飲.i文件是:
%module test
%{
#define SWIG_FILE_WITH_INIT
extern void callMethod(void (*someMethod)());
%}
%typemap (in) void*
%{
$1 = PyCObject_AsVoidPtr($input);
%}
extern void callMethod(void (*someMethod)());
這是我的錯誤:
In [1]: import test
In [2]: b=test.callMethod
In [3]: def func():
...: print "hi"
...:
...:
In [4]: b(func)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
$DIR/<ipython console> in <module>()
TypeError: in method 'callMethod', argument 1 of type 'void (*)()'
我如何用Swig做我想要的?
提前致謝!
找到解決辦法? – JuanPablo 2011-01-17 13:01:15