This example illustrates how you can hook Python to a very simple C program containing a function and a global variable.
/* File : example.c */ /* A global variable */ double Foo = 3.0; /* Compute the greatest common divisor of positive integers */ int gcd(int x, int y) { int g; g = y; while (x > 0) { g = x; x = y % x; y = g; } return g; }
/* File: example.i */ %module example extern int gcd(int x, int y); extern double Foo;
import example
g = example.gcd(42,105)
a = example.cvar.Foo