SWIG/Examples/tcl/variables/

Wrapping C Global Variables

$Header: /cvs/projects/SWIG/Examples/tcl/variables/index.html,v 1.2 2000/08/30 20:31:30 beazley Exp $

When a C global variable appears in an interface file, SWIG tries to wrap it using a technique known as "variable linking." The idea is pretty simple---we try to create a Tcl variable that works exactly like you would expect in a Tcl script, but which magically retrieves or updates the value of the underlying C variable. Click here to see a SWIG interface with some variable declarations in it.

Manipulating Variables from Tcl

Click here to see a script that updates and prints out the values of the variables defined in the above file. Notice how the C global variables work just like normal Tcl variables.

Key points

Creating read-only variables

The %readonly and %readwrite directives can be used to specify a collection of read-only variables. For example:
%readonly
int    status;
double blah;
...
%readwrite
The %readonly directive remains in effect until it is explicitly disabled using the %readwrite directive.

Comments