Używanie SWIG ze wskaźnikiem do funkcji w strukturze C

Usiłuję napisać opakowanie SWIG dla biblioteki C, która używa wskaźników do funkcji w swoich strukturach. Nie potrafię zrozumieć, w jaki sposób obsługiwać struktury zawierające wskaźniki funkcji. Poniżej przedstawiono uproszczony przykład.

test.i:

/* test.i */

%module test
%{

typedef struct {
    int (*my_func)(int);
} test_struct;

int add1(int n) { return n+1; }

test_struct *init_test()
{
    test_struct *t = (test_struct*) malloc(sizeof(test_struct));
    t->my_func = add1;
}
%}

typedef struct {
    int (*my_func)(int);
} test_struct;

extern test_struct *init_test();

przykładowa sesja:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> t = test.init_test()
>>> t
<test.test_struct; proxy of <Swig Object of type 'test_struct *' at 0xa1cafd0> >
>>> t.my_func
<Swig Object of type 'int (*)(int)' at 0xb8009810>
>>> t.my_func(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PySwigObject' object is not callable

Każdy wie, czy to możliwet.my_func (1) zwrócić 2?

Dzięki!

questionAnswers(2)

yourAnswerToTheQuestion