Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | '\" |
2 | '\" Copyright (c) 1989-1993 The Regents of the University of California. | |
3 | '\" Copyright (c) 1994-1997 Sun Microsystems, Inc. | |
4 | '\" Copyright (c) 2000 Scriptics Corporation. | |
5 | '\" | |
6 | '\" See the file "license.terms" for information on usage and redistribution | |
7 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
8 | '\" | |
9 | '\" RCS: @(#) $Id: Eval.3,v 1.12.2.3 2003/07/18 16:56:24 dgp Exp $ | |
10 | '\" | |
11 | '\" The definitions below are for supplemental macros used in Tcl/Tk | |
12 | '\" manual entries. | |
13 | '\" | |
14 | '\" .AP type name in/out ?indent? | |
15 | '\" Start paragraph describing an argument to a library procedure. | |
16 | '\" type is type of argument (int, etc.), in/out is either "in", "out", | |
17 | '\" or "in/out" to describe whether procedure reads or modifies arg, | |
18 | '\" and indent is equivalent to second arg of .IP (shouldn't ever be | |
19 | '\" needed; use .AS below instead) | |
20 | '\" | |
21 | '\" .AS ?type? ?name? | |
22 | '\" Give maximum sizes of arguments for setting tab stops. Type and | |
23 | '\" name are examples of largest possible arguments that will be passed | |
24 | '\" to .AP later. If args are omitted, default tab stops are used. | |
25 | '\" | |
26 | '\" .BS | |
27 | '\" Start box enclosure. From here until next .BE, everything will be | |
28 | '\" enclosed in one large box. | |
29 | '\" | |
30 | '\" .BE | |
31 | '\" End of box enclosure. | |
32 | '\" | |
33 | '\" .CS | |
34 | '\" Begin code excerpt. | |
35 | '\" | |
36 | '\" .CE | |
37 | '\" End code excerpt. | |
38 | '\" | |
39 | '\" .VS ?version? ?br? | |
40 | '\" Begin vertical sidebar, for use in marking newly-changed parts | |
41 | '\" of man pages. The first argument is ignored and used for recording | |
42 | '\" the version when the .VS was added, so that the sidebars can be | |
43 | '\" found and removed when they reach a certain age. If another argument | |
44 | '\" is present, then a line break is forced before starting the sidebar. | |
45 | '\" | |
46 | '\" .VE | |
47 | '\" End of vertical sidebar. | |
48 | '\" | |
49 | '\" .DS | |
50 | '\" Begin an indented unfilled display. | |
51 | '\" | |
52 | '\" .DE | |
53 | '\" End of indented unfilled display. | |
54 | '\" | |
55 | '\" .SO | |
56 | '\" Start of list of standard options for a Tk widget. The | |
57 | '\" options follow on successive lines, in four columns separated | |
58 | '\" by tabs. | |
59 | '\" | |
60 | '\" .SE | |
61 | '\" End of list of standard options for a Tk widget. | |
62 | '\" | |
63 | '\" .OP cmdName dbName dbClass | |
64 | '\" Start of description of a specific option. cmdName gives the | |
65 | '\" option's name as specified in the class command, dbName gives | |
66 | '\" the option's name in the option database, and dbClass gives | |
67 | '\" the option's class in the option database. | |
68 | '\" | |
69 | '\" .UL arg1 arg2 | |
70 | '\" Print arg1 underlined, then print arg2 normally. | |
71 | '\" | |
72 | '\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $ | |
73 | '\" | |
74 | '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. | |
75 | .if t .wh -1.3i ^B | |
76 | .nr ^l \n(.l | |
77 | .ad b | |
78 | '\" # Start an argument description | |
79 | .de AP | |
80 | .ie !"\\$4"" .TP \\$4 | |
81 | .el \{\ | |
82 | . ie !"\\$2"" .TP \\n()Cu | |
83 | . el .TP 15 | |
84 | .\} | |
85 | .ta \\n()Au \\n()Bu | |
86 | .ie !"\\$3"" \{\ | |
87 | \&\\$1 \\fI\\$2\\fP (\\$3) | |
88 | .\".b | |
89 | .\} | |
90 | .el \{\ | |
91 | .br | |
92 | .ie !"\\$2"" \{\ | |
93 | \&\\$1 \\fI\\$2\\fP | |
94 | .\} | |
95 | .el \{\ | |
96 | \&\\fI\\$1\\fP | |
97 | .\} | |
98 | .\} | |
99 | .. | |
100 | '\" # define tabbing values for .AP | |
101 | .de AS | |
102 | .nr )A 10n | |
103 | .if !"\\$1"" .nr )A \\w'\\$1'u+3n | |
104 | .nr )B \\n()Au+15n | |
105 | .\" | |
106 | .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n | |
107 | .nr )C \\n()Bu+\\w'(in/out)'u+2n | |
108 | .. | |
109 | .AS Tcl_Interp Tcl_CreateInterp in/out | |
110 | '\" # BS - start boxed text | |
111 | '\" # ^y = starting y location | |
112 | '\" # ^b = 1 | |
113 | .de BS | |
114 | .br | |
115 | .mk ^y | |
116 | .nr ^b 1u | |
117 | .if n .nf | |
118 | .if n .ti 0 | |
119 | .if n \l'\\n(.lu\(ul' | |
120 | .if n .fi | |
121 | .. | |
122 | '\" # BE - end boxed text (draw box now) | |
123 | .de BE | |
124 | .nf | |
125 | .ti 0 | |
126 | .mk ^t | |
127 | .ie n \l'\\n(^lu\(ul' | |
128 | .el \{\ | |
129 | .\" Draw four-sided box normally, but don't draw top of | |
130 | .\" box if the box started on an earlier page. | |
131 | .ie !\\n(^b-1 \{\ | |
132 | \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' | |
133 | .\} | |
134 | .el \}\ | |
135 | \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' | |
136 | .\} | |
137 | .\} | |
138 | .fi | |
139 | .br | |
140 | .nr ^b 0 | |
141 | .. | |
142 | '\" # VS - start vertical sidebar | |
143 | '\" # ^Y = starting y location | |
144 | '\" # ^v = 1 (for troff; for nroff this doesn't matter) | |
145 | .de VS | |
146 | .if !"\\$2"" .br | |
147 | .mk ^Y | |
148 | .ie n 'mc \s12\(br\s0 | |
149 | .el .nr ^v 1u | |
150 | .. | |
151 | '\" # VE - end of vertical sidebar | |
152 | .de VE | |
153 | .ie n 'mc | |
154 | .el \{\ | |
155 | .ev 2 | |
156 | .nf | |
157 | .ti 0 | |
158 | .mk ^t | |
159 | \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' | |
160 | .sp -1 | |
161 | .fi | |
162 | .ev | |
163 | .\} | |
164 | .nr ^v 0 | |
165 | .. | |
166 | '\" # Special macro to handle page bottom: finish off current | |
167 | '\" # box/sidebar if in box/sidebar mode, then invoked standard | |
168 | '\" # page bottom macro. | |
169 | .de ^B | |
170 | .ev 2 | |
171 | 'ti 0 | |
172 | 'nf | |
173 | .mk ^t | |
174 | .if \\n(^b \{\ | |
175 | .\" Draw three-sided box if this is the box's first page, | |
176 | .\" draw two sides but no top otherwise. | |
177 | .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c | |
178 | .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c | |
179 | .\} | |
180 | .if \\n(^v \{\ | |
181 | .nr ^x \\n(^tu+1v-\\n(^Yu | |
182 | \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c | |
183 | .\} | |
184 | .bp | |
185 | 'fi | |
186 | .ev | |
187 | .if \\n(^b \{\ | |
188 | .mk ^y | |
189 | .nr ^b 2 | |
190 | .\} | |
191 | .if \\n(^v \{\ | |
192 | .mk ^Y | |
193 | .\} | |
194 | .. | |
195 | '\" # DS - begin display | |
196 | .de DS | |
197 | .RS | |
198 | .nf | |
199 | .sp | |
200 | .. | |
201 | '\" # DE - end display | |
202 | .de DE | |
203 | .fi | |
204 | .RE | |
205 | .sp | |
206 | .. | |
207 | '\" # SO - start of list of standard options | |
208 | .de SO | |
209 | .SH "STANDARD OPTIONS" | |
210 | .LP | |
211 | .nf | |
212 | .ta 5.5c 11c | |
213 | .ft B | |
214 | .. | |
215 | '\" # SE - end of list of standard options | |
216 | .de SE | |
217 | .fi | |
218 | .ft R | |
219 | .LP | |
220 | See the \\fBoptions\\fR manual entry for details on the standard options. | |
221 | .. | |
222 | '\" # OP - start of full description for a single option | |
223 | .de OP | |
224 | .LP | |
225 | .nf | |
226 | .ta 4c | |
227 | Command-Line Name: \\fB\\$1\\fR | |
228 | Database Name: \\fB\\$2\\fR | |
229 | Database Class: \\fB\\$3\\fR | |
230 | .fi | |
231 | .IP | |
232 | .. | |
233 | '\" # CS - begin code excerpt | |
234 | .de CS | |
235 | .RS | |
236 | .nf | |
237 | .ta .25i .5i .75i 1i | |
238 | .. | |
239 | '\" # CE - end code excerpt | |
240 | .de CE | |
241 | .fi | |
242 | .RE | |
243 | .. | |
244 | .de UL | |
245 | \\$1\l'|0\(ul'\\$2 | |
246 | .. | |
247 | .TH Tcl_Eval 3 8.1 Tcl "Tcl Library Procedures" | |
248 | .BS | |
249 | .SH NAME | |
250 | Tcl_EvalObjEx, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval, Tcl_VarEvalVA \- execute Tcl scripts | |
251 | .SH SYNOPSIS | |
252 | .nf | |
253 | \fB#include <tcl.h>\fR | |
254 | .sp | |
255 | .VS | |
256 | int | |
257 | \fBTcl_EvalObjEx\fR(\fIinterp, objPtr, flags\fR) | |
258 | .sp | |
259 | int | |
260 | \fBTcl_EvalFile\fR(\fIinterp, fileName\fR) | |
261 | .sp | |
262 | int | |
263 | \fBTcl_EvalObjv\fR(\fIinterp, objc, objv, flags\fR) | |
264 | .sp | |
265 | int | |
266 | \fBTcl_Eval\fR(\fIinterp, script\fR) | |
267 | .sp | |
268 | int | |
269 | \fBTcl_EvalEx\fR(\fIinterp, script, numBytes, flags\fR) | |
270 | .sp | |
271 | int | |
272 | \fBTcl_GlobalEval\fR(\fIinterp, script\fR) | |
273 | .sp | |
274 | int | |
275 | \fBTcl_GlobalEvalObj\fR(\fIinterp, objPtr\fR) | |
276 | .sp | |
277 | int | |
278 | \fBTcl_VarEval\fR(\fIinterp, string, string, ... \fB(char *) NULL\fR) | |
279 | .sp | |
280 | int | |
281 | \fBTcl_VarEvalVA\fR(\fIinterp, argList\fR) | |
282 | .SH ARGUMENTS | |
283 | .AS Tcl_Interp **termPtr; | |
284 | .AP Tcl_Interp *interp in | |
285 | Interpreter in which to execute the script. The interpreter's result is | |
286 | modified to hold the result or error message from the script. | |
287 | .AP Tcl_Obj *objPtr in | |
288 | A Tcl object containing the script to execute. | |
289 | .AP int flags in | |
290 | ORed combination of flag bits that specify additional options. | |
291 | \fBTCL_EVAL_GLOBAL\fR and \fBTCL_EVAL_DIRECT\fR are currently supported. | |
292 | .AP "CONST char" *fileName in | |
293 | Name of a file containing a Tcl script. | |
294 | .AP int objc in | |
295 | The number of objects in the array pointed to by \fIobjPtr\fR; | |
296 | this is also the number of words in the command. | |
297 | .AP Tcl_Obj **objv in | |
298 | Points to an array of pointers to objects; each object holds the | |
299 | value of a single word in the command to execute. | |
300 | .AP int numBytes in | |
301 | The number of bytes in \fIscript\fR, not including any | |
302 | null terminating character. If \-1, then all characters up to the | |
303 | first null byte are used. | |
304 | .AP "CONST char" *script in | |
305 | Points to first byte of script to execute (null-terminated and UTF-8). | |
306 | .AP char *string in | |
307 | String forming part of a Tcl script. | |
308 | .AP va_list argList in | |
309 | An argument list which must have been initialised using | |
310 | \fBTCL_VARARGS_START\fR, and cleared using \fBva_end\fR. | |
311 | .BE | |
312 | ||
313 | .SH DESCRIPTION | |
314 | .PP | |
315 | The procedures described here are invoked to execute Tcl scripts in | |
316 | various forms. | |
317 | \fBTcl_EvalObjEx\fR is the core procedure and is used by many of the others. | |
318 | It executes the commands in the script stored in \fIobjPtr\fR | |
319 | until either an error occurs or the end of the script is reached. | |
320 | If this is the first time \fIobjPtr\fR has been executed, | |
321 | its commands are compiled into bytecode instructions | |
322 | which are then executed. The | |
323 | bytecodes are saved in \fIobjPtr\fR so that the compilation step | |
324 | can be skipped if the object is evaluated again in the future. | |
325 | .PP | |
326 | The return value from \fBTcl_EvalObjEx\fR (and all the other procedures | |
327 | described here) is a Tcl completion code with | |
328 | one of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR, \fBTCL_RETURN\fR, | |
329 | \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR, or possibly some other | |
330 | integer value originating in an extension. | |
331 | In addition, a result value or error message is left in \fIinterp\fR's | |
332 | result; it can be retrieved using \fBTcl_GetObjResult\fR. | |
333 | .PP | |
334 | \fBTcl_EvalFile\fR reads the file given by \fIfileName\fR and evaluates | |
335 | its contents as a Tcl script. It returns the same information as | |
336 | \fBTcl_EvalObjEx\fR. | |
337 | If the file couldn't be read then a Tcl error is returned to describe | |
338 | why the file couldn't be read. | |
339 | .VS 8.4 | |
340 | The eofchar for files is '\\32' (^Z) for all platforms. | |
341 | If you require a ``^Z'' in code for string comparison, you can use | |
342 | ``\\032'' or ``\\u001a'', which will be safely substituted by the Tcl | |
343 | interpreter into ``^Z''. | |
344 | .VE 8.4 | |
345 | .PP | |
346 | \fBTcl_EvalObjv\fR executes a single pre-parsed command instead of a | |
347 | script. The \fIobjc\fR and \fIobjv\fR arguments contain the values | |
348 | of the words for the Tcl command, one word in each object in | |
349 | \fIobjv\fR. \fBTcl_EvalObjv\fR evaluates the command and returns | |
350 | a completion code and result just like \fBTcl_EvalObjEx\fR. | |
351 | .PP | |
352 | \fBTcl_Eval\fR is similar to \fBTcl_EvalObjEx\fR except that the script to | |
353 | be executed is supplied as a string instead of an object and no compilation | |
354 | occurs. The string should be a proper UTF-8 string as converted by | |
355 | \fBTcl_ExternalToUtfDString\fR or \fBTcl_ExternalToUtf\fR when it is known | |
356 | to possibly contain upper ASCII characters who's possible combinations | |
357 | might be a UTF-8 special code. The string is parsed and executed directly | |
358 | (using \fBTcl_EvalObjv\fR) instead of compiling it and executing the | |
359 | bytecodes. In situations where it is known that the script will never be | |
360 | executed again, \fBTcl_Eval\fR may be faster than \fBTcl_EvalObjEx\fR. | |
361 | \fBTcl_Eval\fR returns a completion code and result just like | |
362 | \fBTcl_EvalObjEx\fR. Note: for backward compatibility with versions before | |
363 | Tcl 8.0, \fBTcl_Eval\fR copies the object result in \fIinterp\fR to | |
364 | \fIinterp->result\fR (use is deprecated) where it can be accessed directly. | |
365 | This makes \fBTcl_Eval\fR somewhat slower than \fBTcl_EvalEx\fR, which | |
366 | doesn't do the copy. | |
367 | .PP | |
368 | \fBTcl_EvalEx\fR is an extended version of \fBTcl_Eval\fR that takes | |
369 | additional arguments \fInumBytes\fR and \fIflags\fR. For the | |
370 | efficiency reason given above, \fBTcl_EvalEx\fR is generally preferred | |
371 | over \fBTcl_Eval\fR. | |
372 | .PP | |
373 | \fBTcl_GlobalEval\fR and \fBTcl_GlobalEvalObj\fR are older procedures | |
374 | that are now deprecated. They are similar to \fBTcl_EvalEx\fR and | |
375 | \fBTcl_EvalObjEx\fR except that the script is evaluated in the global | |
376 | namespace and its variable context consists of global variables only | |
377 | (it ignores any Tcl procedures that are active). These functions are | |
378 | equivalent to using the \fBTCL_EVAL_GLOBAL\fR flag (see below). | |
379 | .PP | |
380 | \fBTcl_VarEval\fR takes any number of string arguments | |
381 | of any length, concatenates them into a single string, | |
382 | then calls \fBTcl_Eval\fR to execute that string as a Tcl command. | |
383 | It returns the result of the command and also modifies | |
384 | \fIinterp->result\fR in the same way as \fBTcl_Eval\fR. | |
385 | The last argument to \fBTcl_VarEval\fR must be NULL to indicate the end | |
386 | of arguments. \fBTcl_VarEval\fR is now deprecated. | |
387 | .PP | |
388 | \fBTcl_VarEvalVA\fR is the same as \fBTcl_VarEval\fR except that | |
389 | instead of taking a variable number of arguments it takes an argument | |
390 | list. Like \fBTcl_VarEval\fR, \fBTcl_VarEvalVA\fR is deprecated. | |
391 | ||
392 | .SH "FLAG BITS" | |
393 | Any ORed combination of the following values may be used for the | |
394 | \fIflags\fR argument to procedures such as \fBTcl_EvalObjEx\fR: | |
395 | .TP 23 | |
396 | \fBTCL_EVAL_DIRECT\fR | |
397 | This flag is only used by \fBTcl_EvalObjEx\fR; it is ignored by | |
398 | other procedures. If this flag bit is set, the script is not | |
399 | compiled to bytecodes; instead it is executed directly | |
400 | as is done by \fBTcl_EvalEx\fR. The | |
401 | \fBTCL_EVAL_DIRECT\fR flag is useful in situations where the | |
402 | contents of an object are going to change immediately, so the | |
403 | bytecodes won't be reused in a future execution. In this case, | |
404 | it's faster to execute the script directly. | |
405 | .TP 23 | |
406 | \fBTCL_EVAL_GLOBAL\fR | |
407 | If this flag is set, the script is processed at global level. This | |
408 | means that it is evaluated in the global namespace and its variable | |
409 | context consists of global variables only (it ignores any Tcl | |
410 | procedures at are active). | |
411 | ||
412 | .SH "MISCELLANEOUS DETAILS" | |
413 | .PP | |
414 | During the processing of a Tcl command it is legal to make nested | |
415 | calls to evaluate other commands (this is how procedures and | |
416 | some control structures are implemented). | |
417 | If a code other than \fBTCL_OK\fR is returned | |
418 | from a nested \fBTcl_EvalObjEx\fR invocation, | |
419 | then the caller should normally return immediately, | |
420 | passing that same return code back to its caller, | |
421 | and so on until the top-level application is reached. | |
422 | A few commands, like \fBfor\fR, will check for certain | |
423 | return codes, like \fBTCL_BREAK\fR and \fBTCL_CONTINUE\fR, and process them | |
424 | specially without returning. | |
425 | .PP | |
426 | \fBTcl_EvalObjEx\fR keeps track of how many nested \fBTcl_EvalObjEx\fR | |
427 | invocations are in progress for \fIinterp\fR. | |
428 | If a code of \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR is | |
429 | about to be returned from the topmost \fBTcl_EvalObjEx\fR | |
430 | invocation for \fIinterp\fR, | |
431 | it converts the return code to \fBTCL_ERROR\fR | |
432 | and sets \fIinterp\fR's result to an error message indicating that | |
433 | the \fBreturn\fR, \fBbreak\fR, or \fBcontinue\fR command was | |
434 | invoked in an inappropriate place. | |
435 | This means that top-level applications should never see a return code | |
436 | from \fBTcl_EvalObjEx\fR other then \fBTCL_OK\fR or \fBTCL_ERROR\fR. | |
437 | .VE | |
438 | ||
439 | .SH KEYWORDS | |
440 | execute, file, global, object, result, script |