home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / Interp.3 < prev    next >
Text File  |  1993-04-01  |  6KB  |  133 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/Interp.3,v 1.10 93/04/01 09:25:32 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_Interp tclc
  25. .BS
  26. .SH NAME
  27. Tcl_Interp \- client-visible fields of interpreter structures
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. typedef struct {
  33.     char *\fIresult\fR;
  34.     Tcl_FreeProc *\fIfreeProc\fR;
  35.     int \fIerrorLine\fR;
  36. } Tcl_Interp;
  37.  
  38. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  39. .BE
  40.  
  41. .SH DESCRIPTION
  42. .PP
  43. The \fBTcl_CreateInterp\fR procedure returns a pointer to a Tcl_Interp
  44. structure.  This pointer is then passed into other Tcl procedures
  45. to process commands in the interpreter and perform other operations
  46. on the interpreter.  Interpreter structures contain many many fields
  47. that are used by Tcl, but only three that may be accessed by
  48. clients:  \fIresult\fR, \fIfreeProc\fR, and \fIerrorLine\fR.
  49. .PP
  50. The \fIresult\fR and \fIfreeProc\fR fields are used to return
  51. results or error messages from commands.
  52. This information is returned by command procedures back to \fBTcl_Eval\fR,
  53. and by \fBTcl_Eval\fR back to its callers.
  54. The \fIresult\fR field points to the string that represents the
  55. result or error message, and the \fIfreeProc\fR field tells how
  56. to dispose of the storage for the string when it isn't needed anymore.
  57. The easiest way for command procedures to manipulate these
  58. fields is to call procedures like \fBTcl_SetResult\fR
  59. or \fBTcl_AppendResult\fR;  they
  60. will hide all the details of managing the fields.
  61. The description below is for those procedures that manipulate the
  62. fields directly.
  63. .PP
  64. Whenever a command procedure returns, it must ensure
  65. that the \fIresult\fR field of its interpreter points to the string
  66. being returned by the command.
  67. The \fIresult\fR field must always point to a valid string.
  68. If a command wishes to return no result then \fIinterp->result\fR
  69. should point to an empty string.
  70. Normally, results are assumed to be statically allocated,
  71. which means that the contents will not change before the next time
  72. \fBTcl_Eval\fR is called or some other command procedure is invoked.
  73. In this case, the \fIfreeProc\fR field must be zero.
  74. Alternatively, a command procedure may dynamically
  75. allocate its return value (e.g. using \fBmalloc\fR)
  76. and store a pointer to it in \fIinterp->result\fR.
  77. In this case, the command procedure must also set \fIinterp->freeProc\fR
  78. to the address of a procedure that can free the value (usually \fBfree\fR).
  79. If \fIinterp->freeProc\fR is non-zero, then Tcl will call \fIfreeProc\fR
  80. to free the space pointed to by \fIinterp->result\fR before it
  81. invokes the next command.
  82. If a client procedure overwrites \fIinterp->result\fR when
  83. \fIinterp->freeProc\fR is non-zero, then it is responsible for calling
  84. \fIfreeProc\fR to free the old \fIinterp->result\fR (the \fBTcl_FreeResult\fR
  85. macro should be used for this purpose).
  86. .PP
  87. \fIFreeProc\fR should have arguments and result that match the
  88. \fBTcl_FreeProc\fR declaration above:  it receives a single
  89. argument which is a pointer to the result value to free.
  90. In most applications \fBfree\fR is the only non-zero value ever
  91. used for \fIfreeProc\fR.
  92. However, an application may store a different procedure address
  93. in \fIfreeProc\fR in order to use an alternate memory allocator
  94. or in order to do other cleanup when the result memory is freed.
  95. .PP
  96. As part of processing each command, \fBTcl_Eval\fR initializes
  97. \fIinterp->result\fR
  98. and \fIinterp->freeProc\fR just before calling the command procedure for
  99. the command.  The \fIfreeProc\fR field will be initialized to zero,
  100. and \fIinterp->result\fR will point to an empty string.  Commands that
  101. do not return any value can simply leave the fields alone.
  102. Furthermore, the empty string pointed to by \fIresult\fR is actually
  103. part of an array of \fBTCL_RESULT_SIZE\fR characters (approximately 200).
  104. If a command wishes to return a short string, it can simply copy
  105. it to the area pointed to by \fIinterp->result\fR.  Or, it can use
  106. the sprintf procedure to generate a short result string at the location
  107. pointed to by \fIinterp->result\fR.
  108. .PP
  109. It is a general convention in Tcl-based applications that the result
  110. of an interpreter is normally in the initialized state described
  111. in the previous paragraph.
  112. Procedures that manipulate an interpreter's result (e.g. by
  113. returning an error) will generally assume that the result
  114. has been initialized when the procedure is called.
  115. If such a procedure is to be called after the result has been
  116. changed, then \fBTcl_ResetResult\fR should be called first to
  117. reset the result to its initialized state.
  118. .PP
  119. The \fIerrorLine\fR
  120. field is valid only after \fBTcl_Eval\fR returns
  121. a \fBTCL_ERROR\fR return code.  In this situation the \fIerrorLine\fR
  122. field identifies the line number of the command being executed when
  123. the error occurred.  The line numbers are relative to the command
  124. being executed:  1 means the first line of the command passed to
  125. \fBTcl_Eval\fR, 2 means the second line, and so on.
  126. The \fIerrorLine\fR field is typically used in conjunction with
  127. \fBTcl_AddErrorInfo\fR to report information about where an error
  128. occurred.
  129. \fIErrorLine\fR should not normally be modified except by \fBTcl_Eval\fR.
  130.  
  131. .SH KEYWORDS
  132. free, initialized, interpreter, malloc, result
  133.