First page Back Continue Last page Overview Graphics

struct Example

//boxes.i

%module boxes

%inline %{

struct Box {

double length;

double breadth;

double height;

};

%}

Creating the module:

$ swig -c++ -python boxes.i

$ g++ -fPIC -c boxes_wrap.cxx -I/usr/include/python3.4

$ g++ -shared boxes_wrap.o -o _boxes.so

Using the module in Python3:

>>> import boxes

>>> b = boxes.Box()

>>> b.length = 20

>>> b.width = 8

>>> b.height = 17

>>>

SWIG creates a set of accessor functions for the definition of a structure or union.

The accessor functions generated by SWIG use a pointer to an object and allow access to the individual members.

For example, the declaration :