Passagem de funções python para código C ++ envolto em SWIG
Estou tentando quebrar uma biblioteca C ++ para python, usando SWIG. A biblioteca usa funções de retorno de chamada frequentemente, passandofunções de retorno de chamada de determinado tipo para classificar métodos.
Agora, depois de agrupar o código, eu gostaria de criar a lógica de retorno de chamada do python. Isso é possível? Aqui está um experimento que eu estava fazendo para descobrir .. não funciona no momento.
Os arquivos de cabeçalho e swig são os seguintes:
paska.h:
typedef void (handleri)(int code, char* codename);
// handleri is now an alias to a function that eats int, string and returns void
void wannabe_handleri(int i, char* blah);
void handleri_eater(handleri* h);
paska.i:
%module paska
%{ // this section is copied in the front of the wrapper file
#define SWIG_FILE_WITH_INIT
#include "paska.h"
%}
// from now on, what are we going to wrap ..
%inline %{
// helper functions here
void wannabe_handleri(int i, char* blah) {
};
void handleri_eater(handleri* h) {
};
%}
%include "paska.h"
// in this case, we just put the actual .cpp code into the inline block ..
Finalmente, eu testei em python ..
import paska
def testfunc(i, st):
print i
print st
paska.handleri_eater(paska.wannabe_handleri(1,"eee")) # THIS WORKS!
paska.handleri_eater(testfunc) # THIS DOES NOT WORK!
A última linha me lança "TypeError: no método 'handleri_eater', argumento 1 do tipo 'handleri *'"
Existe alguma maneira de "converter" a função python para um tipo aceito pelo wrapper SWIG?