Default Options for SWIG Python

Given the following function of prototype C:

void my_function(POINTER *p);

How can you use SWIG to create a Python shell that when called:

my_function() ---> he will call my_function(NULL);

my_function(None) ---> he will call my_function(NULL);

my_function(my_pointer) ---> he will call my_function(my_pointer);

+4
source share
1 answer

You want SWIG to generate a default argument NULLfor p. This is possible in one of two ways: Note that it is Noneautomatically passed as a pointer NULL.

1. Use of a "default card" by default ( SWIG doc )

Place the following sample map in the interface file before declaring my_function:

%typemap(default) POINTER *p {
  $1 = NULL;
}

2. ( SWIG)

SWIG :

void my_function(POINTER *p = NULL);

C, SWIG , . %include, C.

+2

All Articles