📄 node11.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.3 Passing Results to/from the Interpreter</TITLE><META NAME="description" CONTENT="3.3.3 Passing Results to/from the Interpreter"><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="node12.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node12.html"><LINK REL="previous" HREF="node10.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node10.html"><LINK REL="up" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html"><LINK REL="next" HREF="node12.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node12.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1310" HREF="node12.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node12.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1304" 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="tex2html1298" HREF="node10.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node10.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1306" 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="tex2html1308" 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="tex2html1311" HREF="node12.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node12.html">3.3.4 Error Reporting and</A><B> Up:</B> <A NAME="tex2html1305" HREF="node8.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node8.html">3.3 Class Tcl</A><B> Previous:</B> <A NAME="tex2html1299" HREF="node10.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node10.html">3.3.2 Invoking OTcl Procedures</A>   <B> <A NAME="tex2html1307" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1309" 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="SECTION02133000000000000000"></A><A NAME="sec:Result"></A><BR>3.3.3 Passing Results to/from the Interpreter</H2><P>When the interpreter invokes a C++ method,it expects the result back in the private member variable,<TT>tcl_-result</TT>.Two methods are available to set this variable.<DL COMPACT><DT><DD>[const char* ]tcl.result../Tcl/Tcl.hTcl::result<P>Pass the result string back to the interpreter.<DT><DD>[const char* fmt, ...]tcl.resultf../Tcl/Tcl2.ccTcl::resultf<P><TT>varargs</TT>(3) variant of above to format the result using <TT>vsprintf</TT>(3), pass the result string back to the interpreter.</DD></DL><PRE> if (strcmp(argv[1], "now") == 0) { {\bfseries{}tcl.resultf}("%.17g", clock()); return TCL_OK; } {\bfseries{}tcl.result}("Invalid operation specified"); return TCL_ERROR;</PRE><P>Likewise, when a C++ method invokes an OTcl command,the interpreter returns the result in <TT>tcl_-result</TT>.<DL COMPACT><DT><DD>tcl.result../Tcl/Tcl.hTcl::result must be used to retrieve the result. Note that the result is a string, that must be converted into an internal format appropriate to the type of result.</DD></DL><PRE> tcl.evalc("Simulator set NumberInterfaces_"); char* ni = {\bfseries{}tcl.result}(); if (atoi(ni) != 1) tcl.evalc("Simulator set NumberInterfaces_ 1");</PRE><P><BR><HR><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -