⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quickstart.html

📁 cpptcl library for ns2
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>C++/Tcl</title></head><body><table style="width: 100%; text-align: left;" border="0" cellpadding="2" cellspacing="20">  <tbody>    <tr>      <td style="vertical-align: top;"><font size="+3"><span style="font-family: helvetica,arial,sans-serif; font-weight: bold; color: rgb(0, 0, 255);">C++/Tcl</span></font><br>      <span style="font-family: helvetica,arial,sans-serif; color: rgb(0, 0, 255); font-weight: bold;">AC++ library for interoperability between C++ and Tcl</span> </td>      <td style="vertical-align: top; text-align: right;"><br>      </td>    </tr>  </tbody></table><br>[<a href="index.html">top</a>][<a href="freefun.html">next</a>]<br><h4>Quick Start</h4>The C++/Tcl library allows to easily integrate these two languages.<br>It is easy to both extend the Tcl interpreter and to embed the Tclinterpreter in a regular C++ code.<br><br><h4><a name="extending"></a>Hello World (extending Tcl)<br></h4>Let's take the following C++ file:<br><br><div style="margin-left: 40px;"><code>// example1.cc<br><br></code><code>#include "cpptcl.h"</code><br><code>#include &lt;iostream&gt;</code><br><code></code><br><code>using namespace std;</code><br><code></code><br><code>void hello()</code><br><code>{</code><br><code>&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Hello C++/Tcl!" &lt;&lt;endl;</code><br><code>}</code><br><code></code><br><code>CPPTCL_MODULE(Mymodule, i)</code><br><code>{</code><br><code>&nbsp;&nbsp;&nbsp;&nbsp; i.def("hello", hello);</code><br><code>}</code><br><code></code></div><br>After compiling (let's suppose that the resulting shared library isnamed <code>mymodule.so</code>), we can do this:<br><br><div style="margin-left: 40px;"><code>$ tclsh</code><br><code>% load ./mymodule.so</code><br><code>% hello</code><br><code>Hello C++/Tcl!</code><br><code>% for {set i 0} {$i != 4} {incr i} { hello }<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>% </code><br><code></code></div><br>In other words, the Tcl interpreter was <span style="font-style: italic;">extended</span> with the loadable module(which is a shared library) that provides the definition of new command.<br><br><h4><a name="embedding"></a>Hello World (embedding Tcl)<br></h4>Let's take the following C++ program:<br><br><div style="margin-left: 40px;"><code>// example2.cc<br><br>#include "cpptcl.h"<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br><br>using namespace std;<br>using namespace Tcl;<br><br>void hello()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Hello C++/Tcl!" &lt;&lt; endl;<br>}<br><br>int main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; interpreter i;<br>&nbsp;&nbsp;&nbsp;&nbsp; i.def("hello", hello);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; string script = "for {set i 0} {$i != 4} {incri} { hello }";<br><br>&nbsp;&nbsp;&nbsp;&nbsp; i.eval(script);<br>}<br></code></div><br>After compiling, it gives the following result:<br><br><div style="margin-left: 40px;"><code>$ ./example2<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>Hello C++/Tcl!<br>$ <br></code></div><br>In other words, the Tcl interpreter exists in a C++ application as aregular object.<br>It is possible to define new commands in this interpreter and executearbitrary Tcl scripts in it, so that C++ and Tcl communicate with eachother.<br><br><br>[<a href="index.html">top</a>][<a href="freefun.html">next</a>]<br><br><hr style="width: 100%; height: 2px;">Copyright &copy; 2004-2006,MaciejSobczak<br><br></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -