Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 1.19 KB

README.md

File metadata and controls

23 lines (20 loc) · 1.19 KB

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.