📄 eval.3
字号:
'\"'\" Copyright (c) 1989-1993 The Regents of the University of California.'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.'\" Copyright (c) 2000 Scriptics Corporation.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: Eval.3,v 1.12 2002/08/05 03:24:39 dgp Exp $'\" .so man.macros.TH Tcl_Eval 3 8.1 Tcl "Tcl Library Procedures".BS.SH NAMETcl_EvalObjEx, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval, Tcl_VarEvalVA \- execute Tcl scripts.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sp.VSint\fBTcl_EvalObjEx\fR(\fIinterp, objPtr, flags\fR).spint\fBTcl_EvalFile\fR(\fIinterp, fileName\fR).spint\fBTcl_EvalObjv\fR(\fIinterp, objc, objv, flags\fR).spint\fBTcl_Eval\fR(\fIinterp, script\fR).spint\fBTcl_EvalEx\fR(\fIinterp, script, numBytes, flags\fR).spint\fBTcl_GlobalEval\fR(\fIinterp, script\fR).spint\fBTcl_GlobalEvalObj\fR(\fIinterp, objPtr, flags\fR).spint\fBTcl_VarEval\fR(\fIinterp, string, string, ... \fB(char *) NULL\fR).spint\fBTcl_VarEvalVA\fR(\fIinterp, argList\fR).SH ARGUMENTS.AS Tcl_Interp **termPtr;.AP Tcl_Interp *interp inInterpreter in which to execute the script. The interpreter's result ismodified to hold the result or error message from the script..AP Tcl_Obj *objPtr inA Tcl object containing the script to execute..AP int flags inORed combination of flag bits that specify additional options.\fBTCL_EVAL_GLOBAL\fR and \fBTCL_EVAL_DIRECT\fR are currently supported..AP "CONST char" *fileName inName of a file containing a Tcl script..AP int objc inThe number of objects in the array pointed to by \fIobjPtr\fR;this is also the number of words in the command..AP Tcl_Obj **objv inPoints to an array of pointers to objects; each object holds thevalue of a single word in the command to execute..AP int numBytes inThe number of bytes in \fIscript\fR, not including anynull terminating character. If \-1, then all characters up to thefirst null byte are used..AP "CONST char" *script inPoints to first byte of script to execute (NULL terminated and UTF-8)..AP char *string inString forming part of a Tcl script..AP va_list argList inAn argument list which must have been initialised using\fBTCL_VARARGS_START\fR, and cleared using \fBva_end\fR..BE.SH DESCRIPTION.PPThe procedures described here are invoked to execute Tcl scripts invarious forms.\fBTcl_EvalObjEx\fR is the core procedure and is used by many of the others.It executes the commands in the script stored in \fIobjPtr\fRuntil either an error occurs or the end of the script is reached.If this is the first time \fIobjPtr\fR has been executed,its commands are compiled into bytecode instructionswhich are then executed. Thebytecodes are saved in \fIobjPtr\fR so that the compilation stepcan be skipped if the object is evaluated again in the future..PPThe return value from \fBTcl_EvalObjEx\fR (and all the other proceduresdescribed here) is a Tcl completion code withone of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR, \fBTCL_RETURN\fR,\fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR.In addition, a result value or error message is left in \fIinterp\fR'sresult; it can be retrieved using \fBTcl_GetObjResult\fR..PP\fBTcl_EvalFile\fR reads the file given by \fIfileName\fR and evaluatesits contents as a Tcl script. It returns the same information as\fBTcl_EvalObjEx\fR.If the file couldn't be read then a Tcl error is returned to describewhy the file couldn't be read..VS 8.4The eofchar for files is '\\32' (^Z) for all platforms.If you require a ``^Z'' in code for string comparison, you can use``\\032'' or ``\\u001a'', which will be safely substituted by the Tclinterpreter into ``^Z''..VE 8.4.PP\fBTcl_EvalObjv\fR executes a single pre-parsed command instead of ascript. The \fIobjc\fR and \fIobjv\fR arguments contain the valuesof the words for the Tcl command, one word in each object in\fIobjv\fR. \fBTcl_EvalObjv\fR evaluates the command and returnsa completion code and result just like \fBTcl_EvalObjEx\fR..PP\fBTcl_Eval\fR is similar to \fBTcl_EvalObjEx\fR except that the script tobe executed is supplied as a string instead of an object and no compilationoccurs. The string should be a proper UTF-8 string as converted by\fBTcl_ExternalToUtfDString\fR or \fBTcl_ExternalToUtf\fR when it is knownto possibly contain upper ASCII characters who's possible combinationsmight be a UTF-8 special code. The string is parsed and executed directly(using \fBTcl_EvalObjv\fR) instead of compiling it and executing thebytecodes. In situations where it is known that the script will never beexecuted again, \fBTcl_Eval\fR may be faster than \fBTcl_EvalObjEx\fR. \fBTcl_Eval\fR returns a completion code and result just like \fBTcl_EvalObjEx\fR. Note: for backward compatibility with versions beforeTcl 8.0, \fBTcl_Eval\fR copies the object result in \fIinterp\fR to\fIinterp->result\fR (use is deprecated) where it can be accessed directly. This makes \fBTcl_Eval\fR somewhat slower than \fBTcl_EvalEx\fR, whichdoesn't do the copy..PP\fBTcl_EvalEx\fR is an extended version of \fBTcl_Eval\fR that takesadditional arguments \fInumBytes\fR and \fIflags\fR. For theefficiency reason given above, \fBTcl_EvalEx\fR is generally preferredover \fBTcl_Eval\fR..PP\fBTcl_GlobalEval\fR and \fBTcl_GlobalEvalObj\fR are older proceduresthat are now deprecated. They are similar to \fBTcl_EvalEx\fR and\fBTcl_EvalObjEx\fR except that the script is evaluated in the globalnamespace and its variable context consists of global variables only(it ignores any Tcl procedures that are active). These functions areequivalent to using the \fBTCL_EVAL_GLOBAL\fR flag (see below)..PP\fBTcl_VarEval\fR takes any number of string argumentsof any length, concatenates them into a single string,then calls \fBTcl_Eval\fR to execute that string as a Tcl command.It returns the result of the command and also modifies\fIinterp->result\fR in the same way as \fBTcl_Eval\fR.The last argument to \fBTcl_VarEval\fR must be NULL to indicate the endof arguments. \fBTcl_VarEval\fR is now deprecated..PP\fBTcl_VarEvalVA\fR is the same as \fBTcl_VarEval\fR except thatinstead of taking a variable number of arguments it takes an argumentlist. Like \fBTcl_VarEval\fR, \fBTcl_VarEvalVA\fR is deprecated..SH "FLAG BITS"Any ORed combination of the following values may be used for the\fIflags\fR argument to procedures such as \fBTcl_EvalObjEx\fR:.TP 23\fBTCL_EVAL_DIRECT\fRThis flag is only used by \fBTcl_EvalObjEx\fR; it is ignored byother procedures. If this flag bit is set, the script is notcompiled to bytecodes; instead it is executed directlyas is done by \fBTcl_EvalEx\fR. The\fBTCL_EVAL_DIRECT\fR flag is useful in situations where thecontents of an object are going to change immediately, so thebytecodes won't be reused in a future execution. In this case,it's faster to execute the script directly..TP 23\fBTCL_EVAL_GLOBAL\fRIf this flag is set, the script is processed at global level. Thismeans that it is evaluated in the global namespace and its variablecontext consists of global variables only (it ignores any Tclprocedures at are active)..SH "MISCELLANEOUS DETAILS".PPDuring the processing of a Tcl command it is legal to make nestedcalls to evaluate other commands (this is how procedures andsome control structures are implemented).If a code other than \fBTCL_OK\fR is returnedfrom a nested \fBTcl_EvalObjEx\fR invocation,then the caller should normally return immediately,passing that same return code back to its caller,and so on until the top-level application is reached.A few commands, like \fBfor\fR, will check for certainreturn codes, like \fBTCL_BREAK\fR and \fBTCL_CONTINUE\fR, and process themspecially without returning..PP\fBTcl_EvalObjEx\fR keeps track of how many nested \fBTcl_EvalObjEx\fRinvocations are in progress for \fIinterp\fR.If a code of \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR isabout to be returned from the topmost \fBTcl_EvalObjEx\fRinvocation for \fIinterp\fR,it converts the return code to \fBTCL_ERROR\fRand sets \fIinterp\fR's result to an error message indicating thatthe \fBreturn\fR, \fBbreak\fR, or \fBcontinue\fR command wasinvoked in an inappropriate place.This means that top-level applications should never see a return codefrom \fBTcl_EvalObjEx\fR other then \fBTCL_OK\fR or \fBTCL_ERROR\fR..VE.SH KEYWORDSexecute, file, global, object, result, script
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -