Debian Codegraph @

doc/SetVar.3

raw
1 '\"
2 '\" Copyright (c) 1989-1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH Tcl_SetVar 3 8.1 Tcl "Tcl Library Procedures"
9 .so man.macros
10 .BS
11 .SH NAME
12 Tcl_SetVar2Ex, Tcl_SetVar, Tcl_SetVar2, Tcl_ObjSetVar2, Tcl_GetVar2Ex, Tcl_GetVar, Tcl_GetVar2, Tcl_ObjGetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
13 .SH SYNOPSIS
14 .nf
15 \fB#include <tcl.h>\fR
16 .sp
17 Tcl_Obj *
18 \fBTcl_SetVar2Ex\fR(\fIinterp, name1, name2, newValuePtr, flags\fR)
19 .sp
20 const char *
21 \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
22 .sp
23 const char *
24 \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
25 .sp
26 Tcl_Obj *
27 \fBTcl_ObjSetVar2\fR(\fIinterp, part1Ptr, part2Ptr, newValuePtr, flags\fR)
28 .sp
29 Tcl_Obj *
30 \fBTcl_GetVar2Ex\fR(\fIinterp, name1, name2, flags\fR)
31 .sp
32 const char *
33 \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
34 .sp
35 const char *
36 \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
37 .sp
38 Tcl_Obj *
39 \fBTcl_ObjGetVar2\fR(\fIinterp, part1Ptr, part2Ptr, flags\fR)
40 .sp
41 int
42 \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
43 .sp
44 int
45 \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
46 .SH ARGUMENTS
47 .AS Tcl_Interp *newValuePtr
48 .AP Tcl_Interp *interp in
49 Interpreter containing variable.
50 .AP "const char" *name1 in
51 Contains the name of an array variable (if \fIname2\fR is non-NULL)
52 or (if \fIname2\fR is NULL) either the name of a scalar variable
53 or a complete name including both variable name and index.
54 May include \fB::\fR namespace qualifiers
55 to specify a variable in a particular namespace.
56 .AP "const char" *name2 in
57 If non-NULL, gives name of element within array; in this
58 case \fIname1\fR must refer to an array variable.
59 .AP Tcl_Obj *newValuePtr in
60 Points to a Tcl value containing the new value for the variable.
61 .AP int flags in
62 OR-ed combination of bits providing additional information. See below
63 for valid values.
64 .AP "const char" *varName in
65 Name of variable.
66 May include \fB::\fR namespace qualifiers
67 to specify a variable in a particular namespace.
68 May refer to a scalar variable or an element of
69 an array.
70 .AP "const char" *newValue in
71 New value for variable, specified as a null-terminated string.
72 A copy of this value is stored in the variable.
73 .AP Tcl_Obj *part1Ptr in
74 Points to a Tcl value containing the variable's name.
75 The name may include a series of \fB::\fR namespace qualifiers
76 to specify a variable in a particular namespace.
77 May refer to a scalar variable or an element of an array variable.
78 .AP Tcl_Obj *part2Ptr in
79 If non-NULL, points to a value containing the name of an element
80 within an array and \fIpart1Ptr\fR must refer to an array variable.
81 .BE
82
83 .SH DESCRIPTION
84 .PP
85 These procedures are used to create, modify, read, and delete
86 Tcl variables from C code.
87 .PP
88 \fBTcl_SetVar2Ex\fR, \fBTcl_SetVar\fR, \fBTcl_SetVar2\fR, and
89 \fBTcl_ObjSetVar2\fR
90 will create a new variable or modify an existing one.
91 These procedures set the given variable to the value
92 given by \fInewValuePtr\fR or \fInewValue\fR and return a
93 pointer to the variable's new value, which is stored in Tcl's
94 variable structure.
95 \fBTcl_SetVar2Ex\fR and \fBTcl_ObjSetVar2\fR take the new value as a
96 Tcl_Obj and return
97 a pointer to a Tcl_Obj. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR
98 take the new value as a string and return a string; they are
99 usually less efficient than \fBTcl_ObjSetVar2\fR. Note that the
100 return value may be different than the \fInewValuePtr\fR or
101 \fInewValue\fR argument, due to modifications made by write traces.
102 If an error occurs in setting the variable (e.g. an array
103 variable is referenced without giving an index into the array)
104 NULL is returned and an error message is left in \fIinterp\fR's
105 result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR bit is set.
106 .PP
107 \fBTcl_GetVar2Ex\fR, \fBTcl_GetVar\fR, \fBTcl_GetVar2\fR, and
108 \fBTcl_ObjGetVar2\fR
109 return the current value of a variable.
110 The arguments to these procedures are treated in the same way
111 as the arguments to the procedures described above.
112 Under normal circumstances, the return value is a pointer
113 to the variable's value. For \fBTcl_GetVar2Ex\fR and
114 \fBTcl_ObjGetVar2\fR the value is
115 returned as a pointer to a Tcl_Obj. For \fBTcl_GetVar\fR and
116 \fBTcl_GetVar2\fR the value is returned as a string; this is
117 usually less efficient, so \fBTcl_GetVar2Ex\fR or \fBTcl_ObjGetVar2\fR
118 are preferred.
119 If an error occurs while reading the variable (e.g. the variable
120 does not exist or an array element is specified for a scalar
121 variable), then NULL is returned and an error message is left
122 in \fIinterp\fR's result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR
123 bit is set.
124 .PP
125 \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
126 a variable, so that future attempts to read the variable will return
127 an error.
128 The arguments to these procedures are treated in the same way
129 as the arguments to the procedures above.
130 If the variable is successfully removed then \fBTCL_OK\fR is returned.
131 If the variable cannot be removed because it does not exist then
132 \fBTCL_ERROR\fR is returned and an error message is left
133 in \fIinterp\fR's result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR
134 bit is set.
135 If an array element is specified, the given element is removed
136 but the array remains.
137 If an array name is specified without an index, then the entire
138 array is removed.
139 .PP
140 The name of a variable may be specified to these procedures in
141 four ways:
142 .IP [1]
143 If \fBTcl_SetVar\fR, \fBTcl_GetVar\fR, or \fBTcl_UnsetVar\fR
144 is invoked, the variable name is given as
145 a single string, \fIvarName\fR.
146 If \fIvarName\fR contains an open parenthesis and ends with a
147 close parenthesis, then the value between the parentheses is
148 treated as an index (which can have any string value) and
149 the characters before the first open
150 parenthesis are treated as the name of an array variable.
151 If \fIvarName\fR does not have parentheses as described above, then
152 the entire string is treated as the name of a scalar variable.
153 .IP [2]
154 If the \fIname1\fR and \fIname2\fR arguments are provided and
155 \fIname2\fR is non-NULL, then an array element is specified and
156 the array name and index have
157 already been separated by the caller: \fIname1\fR contains the
158 name and \fIname2\fR contains the index. An error is generated
159 if \fIname1\fR contains an open parenthesis and ends with a
160 close parenthesis (array element) and \fIname2\fR is non-NULL.
161 .IP [3]
162 If \fIname2\fR is NULL, \fIname1\fR is treated just like
163 \fIvarName\fR in case [1] above (it can be either a scalar or an array
164 element variable name).
165 .PP
166 The \fIflags\fR argument may be used to specify any of several
167 options to the procedures.
168 It consists of an OR-ed combination of the following bits.
169 .TP
170 \fBTCL_GLOBAL_ONLY\fR
171 Under normal circumstances the procedures look up variables as follows.
172 If a procedure call is active in \fIinterp\fR,
173 the variable is looked up at the current level of procedure call.
174 Otherwise, the variable is looked up first in the current namespace,
175 then in the global namespace.
176 However, if this bit is set in \fIflags\fR then the variable
177 is looked up only in the global namespace
178 even if there is a procedure call active.
179 If both \fBTCL_GLOBAL_ONLY\fR and \fBTCL_NAMESPACE_ONLY\fR are given,
180 \fBTCL_GLOBAL_ONLY\fR is ignored.
181 .TP
182 \fBTCL_NAMESPACE_ONLY\fR
183 If this bit is set in \fIflags\fR then the variable
184 is looked up only in the current namespace; if a procedure is active
185 its variables are ignored, and the global namespace is also ignored unless
186 it is the current namespace.
187 .TP
188 \fBTCL_LEAVE_ERR_MSG\fR
189 If an error is returned and this bit is set in \fIflags\fR, then
190 an error message will be left in the interpreter's result,
191 where it can be retrieved with \fBTcl_GetObjResult\fR
192 or \fBTcl_GetStringResult\fR.
193 If this flag bit is not set then no error message is left
194 and the interpreter's result will not be modified.
195 .TP
196 \fBTCL_APPEND_VALUE\fR
197 If this bit is set then \fInewValuePtr\fR or \fInewValue\fR is
198 appended to the current value instead of replacing it.
199 If the variable is currently undefined, then the bit is ignored.
200 This bit is only used by the \fBTcl_Set*\fR procedures.
201 .TP
202 \fBTCL_LIST_ELEMENT\fR
203 If this bit is set, then \fInewValue\fR is converted to a valid
204 Tcl list element before setting (or appending to) the variable.
205 A separator space is appended before the new list element unless
206 the list element is going to be the first element in a list or
207 sublist (i.e. the variable's current value is empty, or contains
208 the single character
209 .QW { ,
210 or ends in
211 .QW " }" ).
212 When appending, the original value of the variable must also be
213 a valid list, so that the operation is the appending of a new
214 list element onto a list.
215 .PP
216 \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR
217 return the current value of a variable.
218 The arguments to these procedures are treated in the same way
219 as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
220 Under normal circumstances, the return value is a pointer
221 to the variable's value (which is stored in Tcl's variable
222 structure and will not change before the next call to \fBTcl_SetVar\fR
223 or \fBTcl_SetVar2\fR).
224 \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR use the flag bits \fBTCL_GLOBAL_ONLY\fR
225 and \fBTCL_LEAVE_ERR_MSG\fR, both of
226 which have
227 the same meaning as for \fBTcl_SetVar\fR.
228 If an error occurs in reading the variable (e.g. the variable
229 does not exist or an array element is specified for a scalar
230 variable), then NULL is returned.
231 .PP
232 \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
233 a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
234 for the variable will return an error.
235 The arguments to these procedures are treated in the same way
236 as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
237 If the variable is successfully removed then \fBTCL_OK\fR is returned.
238 If the variable cannot be removed because it does not exist then
239 \fBTCL_ERROR\fR is returned.
240 If an array element is specified, the given element is removed
241 but the array remains.
242 If an array name is specified without an index, then the entire
243 array is removed.
244
245 .SH "SEE ALSO"
246 Tcl_GetObjResult, Tcl_GetStringResult, Tcl_TraceVar
247
248 .SH KEYWORDS
249 array, get variable, interpreter, scalar, set, unset, value, variable