Skip to content

kei91/SWIG-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWIG-example

This is a simple example of using SWIG. It covers two topics:

  • Wrapping C++ class "sample" in Python.
  • Calling Python script with wrapped class from C++.

For more information about project setting, look here.

Class sample (/sample/sample.h) contains three functions that we want call from Python script:

  • print_infoA(A *a)
  • print_infoVoid(void *a)
  • print_info(int i)

First function takes pointer to class A (/A/A.h).

For first two we have to put these lines in sample.i:

%typemap(in) void* { $1 = (void *)PyCapsule_GetPointer($input, "testVoid.pointer"); }

%typemap(in) A* { $1 = (A *)PyCapsule_GetPointer($input, "testA.pointer"); }

After that we can call function that takes void* or A* parameters.

Test Python script placed in /sample/test.py.

/startpy/startpy.cpp contains function pythonFunc that calls test.py.

About

Wrapping a C++ class in Python using SWIG.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published