This example illustrates how you can hook Tcl 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;
load ./example.so
set g [gcd 42 105]
set a $Foo set Foo $newvalue