4

Here is my c++ code:

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

My Swig .i file is:

%module test
%{
#define SWIG_FILE_WITH_INIT

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

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


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

Here is my error:

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

How can I do what I want with Swig?

Thanks in advance!

0

1 Answer 1

1

Pointers to functions and callbacks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.