[25] | 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 | '\" RCS: @(#) $Id: ExprLong.3,v 1.15 2007/12/13 15:22:31 dgp Exp $ |
---|
| 9 | '\" |
---|
| 10 | .so man.macros |
---|
| 11 | .TH Tcl_ExprLong 3 7.0 Tcl "Tcl Library Procedures" |
---|
| 12 | .BS |
---|
| 13 | .SH NAME |
---|
| 14 | Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString \- evaluate an expression |
---|
| 15 | .SH SYNOPSIS |
---|
| 16 | .nf |
---|
| 17 | \fB#include <tcl.h>\fR |
---|
| 18 | .sp |
---|
| 19 | int |
---|
| 20 | \fBTcl_ExprLong\fR(\fIinterp, expr, longPtr\fR) |
---|
| 21 | .sp |
---|
| 22 | int |
---|
| 23 | \fBTcl_ExprDouble\fR(\fIinterp, expr, doublePtr\fR) |
---|
| 24 | .sp |
---|
| 25 | int |
---|
| 26 | \fBTcl_ExprBoolean\fR(\fIinterp, expr, booleanPtr\fR) |
---|
| 27 | .sp |
---|
| 28 | int |
---|
| 29 | \fBTcl_ExprString\fR(\fIinterp, expr\fR) |
---|
| 30 | .SH ARGUMENTS |
---|
| 31 | .AS Tcl_Interp *booleanPtr out |
---|
| 32 | .AP Tcl_Interp *interp in |
---|
| 33 | Interpreter in whose context to evaluate \fIexpr\fR. |
---|
| 34 | .AP "const char" *expr in |
---|
| 35 | Expression to be evaluated. |
---|
| 36 | .AP long *longPtr out |
---|
| 37 | Pointer to location in which to store the integer value of the |
---|
| 38 | expression. |
---|
| 39 | .AP int *doublePtr out |
---|
| 40 | Pointer to location in which to store the floating-point value of the |
---|
| 41 | expression. |
---|
| 42 | .AP int *booleanPtr out |
---|
| 43 | Pointer to location in which to store the 0/1 boolean value of the |
---|
| 44 | expression. |
---|
| 45 | .BE |
---|
| 46 | |
---|
| 47 | .SH DESCRIPTION |
---|
| 48 | .PP |
---|
| 49 | These four procedures all evaluate the expression |
---|
| 50 | given by the \fIexpr\fR argument |
---|
| 51 | and return the result in one of four different forms. |
---|
| 52 | The expression can have any of the forms accepted by the \fBexpr\fR command. |
---|
| 53 | Note that these procedures have been largely replaced by the |
---|
| 54 | object-based procedures \fBTcl_ExprLongObj\fR, \fBTcl_ExprDoubleObj\fR, |
---|
| 55 | \fBTcl_ExprBooleanObj\fR, and \fBTcl_ExprObj\fR. |
---|
| 56 | Those object-based procedures evaluate an expression held in a Tcl object |
---|
| 57 | instead of a string. |
---|
| 58 | The object argument can retain an internal representation |
---|
| 59 | that is more efficient to execute. |
---|
| 60 | .PP |
---|
| 61 | The \fIinterp\fR argument refers to an interpreter used to |
---|
| 62 | evaluate the expression (e.g. for variables and nested Tcl |
---|
| 63 | commands) and to return error information. |
---|
| 64 | .PP |
---|
| 65 | For all of these procedures the return value is a standard |
---|
| 66 | Tcl result: \fBTCL_OK\fR means the expression was successfully |
---|
| 67 | evaluated, and \fBTCL_ERROR\fR means that an error occurred while |
---|
| 68 | evaluating the expression. |
---|
| 69 | If \fBTCL_ERROR\fR is returned then |
---|
| 70 | the interpreter's result will hold a message describing the error. |
---|
| 71 | If an error occurs while executing a Tcl command embedded in |
---|
| 72 | the expression then that error will be returned. |
---|
| 73 | .PP |
---|
| 74 | If the expression is successfully evaluated, then its value is |
---|
| 75 | returned in one of four forms, depending on which procedure |
---|
| 76 | is invoked. |
---|
| 77 | \fBTcl_ExprLong\fR stores an integer value at \fI*longPtr\fR. |
---|
| 78 | If the expression's actual value is a floating-point number, |
---|
| 79 | then it is truncated to an integer. |
---|
| 80 | If the expression's actual value is a non-numeric string then |
---|
| 81 | an error is returned. |
---|
| 82 | .PP |
---|
| 83 | \fBTcl_ExprDouble\fR stores a floating-point value at \fI*doublePtr\fR. |
---|
| 84 | If the expression's actual value is an integer, it is converted to |
---|
| 85 | floating-point. |
---|
| 86 | If the expression's actual value is a non-numeric string then |
---|
| 87 | an error is returned. |
---|
| 88 | .PP |
---|
| 89 | \fBTcl_ExprBoolean\fR stores a 0/1 integer value at \fI*booleanPtr\fR. |
---|
| 90 | If the expression's actual value is an integer or floating-point |
---|
| 91 | number, then they store 0 at \fI*booleanPtr\fR if |
---|
| 92 | the value was zero and 1 otherwise. |
---|
| 93 | If the expression's actual value is a non-numeric string then |
---|
| 94 | it must be one of the values accepted by \fBTcl_GetBoolean\fR |
---|
| 95 | such as |
---|
| 96 | .QW yes |
---|
| 97 | or |
---|
| 98 | .QW no , |
---|
| 99 | or else an error occurs. |
---|
| 100 | .PP |
---|
| 101 | \fBTcl_ExprString\fR returns the value of the expression as a |
---|
| 102 | string stored in the interpreter's result. |
---|
| 103 | |
---|
| 104 | .SH "SEE ALSO" |
---|
| 105 | Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj |
---|
| 106 | |
---|
| 107 | .SH KEYWORDS |
---|
| 108 | boolean, double, evaluate, expression, integer, object, string |
---|