2010-07-21 6 views
4

Voici mon C++ Code:Appel d'une fonction Python en C++ avec Swig

void callMethod(void (*someMethod)()) { 
    (*someMethod)(); 
} 

Mon Swig fichier .i est:

%module test 
%{ 
#define SWIG_FILE_WITH_INIT 

extern void callMethod(void (*someMethod)()); 
%} 

%typemap (in) void* 
%{ 
    $1 = PyCObject_AsVoidPtr($input); 
%} 


extern void callMethod(void (*someMethod)()); 

Voici mon erreur:

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 (*)()' 

Comment puis-je faire ce que je veux avec Swig?

Merci d'avance!

+0

trouver la solution? – JuanPablo

Répondre