#include <tcl.h> char * Tcl_SetVar(interp, varName, newValue, flags) char * Tcl_SetVar2(interp, name1, name2, newValue, flags) char * Tcl_GetVar(interp, varName, flags) char * Tcl_GetVar2(interp, name1, name2, flags) int Tcl_UnsetVar(interp, varName, flags) int Tcl_UnsetVar2(interp, name1, name2, flags)
Note that Tcl_GetVar and Tcl_SetVar have been largely replaced by the object-based procedures Tcl_ObjGetVar2 and Tcl_ObjSetVar2. Those object-based procedures read, modify, and create a variable whose name is held in a Tcl object instead of a string. They also return a pointer to the object which is the variable's value instead of returning a string. Operations on objects can be faster since objects hold an internal representation that can be manipulated more efficiently.
Tcl_SetVar and Tcl_SetVar2 will create a new variable or modify an existing one. Both of these procedures set the given variable to the value given by newValue, and they return a pointer to a copy of the variable's new value, which is stored in Tcl's variable structure. Tcl keeps a private copy of the variable's value, so the caller may change newValue after these procedures return without affecting the value of the variable. If an error occurs in setting the variable (e.g. an array variable is referenced without giving an index into the array), they return NULL.
The name of the variable may be specified to Tcl_SetVar and Tcl_SetVar2 in either of two ways. If Tcl_SetVar is called, the variable name is given as a single string, varName. If varName contains an open parenthesis and ends with a close parenthesis, then the value between the parentheses is treated as an index (which can have any string value) and the characters before the first open parenthesis are treated as the name of an array variable. If varName doesn't have parentheses as described above, then the entire string is treated as the name of a scalar variable. If Tcl_SetVar2 is called, then the array name and index have been separated by the caller into two separate strings, name1 and name2 respectively; if name2 is zero it means that a scalar variable is being referenced.
The flags argument may be used to specify any of several options to the procedures. It consists of an OR-ed combination of any of the following bits:
Copyright © 1989-1994 The Regents of the University of California.
Copyright © 1994-1997 Sun Microsystems, Inc.