next up previous contents index
Next: tclcmd Up: tcl++ Previous: Creating a Tcl command   Contents   Index


Tcl variables can be accessed by means of the tclvar class. For example, if the programmer declares:

tclvar hello("hello"); float floatvar;

then the variable hello can be used just like a normal C variable in expression such as


The class allows assignment to and from double and char* variables, incrementing and decrementing the variables, compound assignment and accessing array Tcl variables by means of the C array syntax. The is also a function that tests for the existence of a Tcl variable.

The complete class definition is given by:

class tclvar

/* constructors */
  tclvar(char *nm, char* val=NULL);

/* These four statements allow tclvars to be freely mixed with arithmetic 
 expressions */
  double operator=(double x);
  char* operator=(char* x);
  operator double ();
  operator char* ();

  double operator++();
  double operator++(int);
  double operator--();
  double operator--(int); 
  double operator+=(double x);
  double operator-=(double x);
  double operator*=(double x);
  double operator/=(double x);

  tclvar operator=(tclvar x); 
/* arrays can be indexed either by integers, or by strings */
  tclvar operator[](int index);
  tclvar operator[](char* index);

  friend int exists(tclvar x);

Russell Standish 2016-09-02