📄 node10.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by: Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>3.3.2 Invoking OTcl Procedures</TITLE><META NAME="description" CONTENT="3.3.2 Invoking OTcl Procedures"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html"><LINK REL="previous" HREF="node9.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node9.html"><LINK REL="up" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html"><LINK REL="next" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1296" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1290" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1284" HREF="node9.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node9.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1292" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1294" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1297" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html">3.3.3 Passing Results to/from</A><B> Up:</B> <A NAME="tex2html1291" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html">3.3 Class Tcl</A><B> Previous:</B> <A NAME="tex2html1285" HREF="node9.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node9.html">3.3.1 Obtain a Reference</A>   <B> <A NAME="tex2html1293" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1295" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H2><A NAME="SECTION02132000000000000000"></A><A NAME="sec:Invoke"></A><BR>3.3.2 Invoking OTcl Procedures</H2>There are four different methods to invoke an OTcl commandthrough the instance, <TT>tcl</TT>.They differ essentially in their calling arguments.Each function passes a string to the interpreter,that then evaluates the string in a global context.These methods will return to the caller if the interpreter returns TCL_OK.On the other hand, if the interpreter returns TCL_ERROR,the methods will call tkerror.The user can overload this procedure to selectively disregardcertain types of errors.Such intricacies of OTcl programming are outside thescope of this document.The next sectionSectionsec:Resultdescribes methods to access the result returned by the interpreter.<UL><LI>[char* ]tcl.eval../Tcl/Tcl.ccTcl::eval invokes []Tcl_GlobalEval to execute through the interpreter.<P></LI><LI>[const char* ]tcl.evalc../Tcl/Tcl.ccTcl::evalc preserves the argument string . It copies the string into its internal buffer; it then invokes the previous [char* ]eval on the internal buffer.<P></LI><LI>[]tcl.eval../Tcl/Tcl.ccTcl::eval assumes that the command is already stored in the class' internal <TT>bp_</TT>; it directly invokes [char* bp_]tcl.eval. A handle to the buffer itself is available through the method tcl.buffer../Tcl/Tcl.hTcl::buffer.<P></LI><LI>[const char* , ...]tcl.evalf../Tcl/Tcl2.ccTcl::evalf is a <TT>Printf</TT>(3) like equivalent. It uses <TT>vsprintf</TT>(3) internally to create the input string.</LI></UL>As an example, here are some of the ways of using the above methods:<PRE> Tcl& tcl = {\bfseries{}Tcl::instance}(); char wrk[128]; strcpy(wrk, "Simulator set NumberInterfaces_ 1"); {\bfseries{}tcl.eval}(wrk); sprintf({\bfseries{}tcl.buffer}(), "Agent/SRM set requestFunction_ %s", "Fixed"); {\bfseries{}tcl.eval}(); {\bfseries{}tcl.evalc}("puts stdout {hello world}"); {\bfseries{}tcl.evalf}("%s request %d %d", name_, sender, msgid);</PRE><P><HR><!--Navigation Panel--><A NAME="tex2html1296" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1290" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1284" HREF="node9.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node9.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1292" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1294" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1297" HREF="node11.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node11.html">3.3.3 Passing Results to/from</A><B> Up:</B> <A NAME="tex2html1291" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html">3.3 Class Tcl</A><B> Previous:</B> <A NAME="tex2html1285" HREF="node9.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node9.html">3.3.1 Obtain a Reference</A>   <B> <A NAME="tex2html1293" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1295" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -