tcl.html

来自「perl教程」· HTML 代码 · 共 508 行 · 第 1/2 页

HTML
508 行
字号
</dd>
</li>
<dt><strong><a name="item_ev">Tcl::Ev (FIELD, ...)</a></strong>

<dd>
<p>Used to declare %-substitution variables of interest to a subroutine
callback.  FIELD is expected to be of the form &quot;%#&quot; where # is a single
character, and multiple fields may be specified.  Returns a blessed object
that the 'call' method will recognize when it is passed as the first
argument to a subroutine in a callback.  See description of 'call' method
for details.</p>
</dd>
</li>
<dt><strong><a name="item_result">result ()</a></strong>

<dd>
<p>Returns the current Tcl interpreter result. List v. scalar context is
handled as in <em>Eval</em>() above.</p>
</dd>
</li>
<dt><strong><a name="item_createcommand">CreateCommand (CMDNAME, CMDPROC, CLIENTDATA, DELETEPROC)</a></strong>

<dd>
<p>Binds a new procedure named CMDNAME into the interpreter. The
CLIENTDATA and DELETEPROC arguments are optional. There are two cases:</p>
</dd>
<dd>
<p>(1) CMDPROC is the address of a C function</p>
</dd>
<dd>
<p>(presumably obtained using <em>dl_open</em> and <em>dl_find_symbol</em>. In this case
CLIENTDATA and DELETEPROC are taken to be raw data of the ClientData and
deleteProc field presumably obtained in a similar way.</p>
</dd>
<dd>
<p>(2) CMDPROC is a Perl subroutine</p>
</dd>
<dd>
<p>(either a sub name, a sub reference or an anonymous sub). In this case
CLIENTDATA can be any perl scalar (e.g. a ref to some other data) and
DELETEPROC must be a perl sub too. When CMDNAME is invoked in the Tcl
interpeter, the arguments passed to the Perl sub CMDPROC are</p>
</dd>
<dd>
<pre>
    (CLIENTDATA, INTERP, LIST)</pre>
</dd>
<dd>
<p>where INTERP is a Perl object for the Tcl interpreter which called out
and LIST is a Perl list of the arguments CMDNAME was called with.
As usual in Tcl, the first element of the list is CMDNAME itself.
When CMDNAME is deleted from the interpreter (either explicitly with
<em>DeleteCommand</em> or because the destructor for the interpeter object
is called), it is passed the single argument CLIENTDATA.</p>
</dd>
</li>
<dt><strong><a name="item_deletecommand">DeleteCommand (CMDNAME)</a></strong>

<dd>
<p>Deletes command CMDNAME from the interpreter. If the command was created
with a DELETEPROC (see <em>CreateCommand</em> above), then it is invoked at
this point. When a Tcl interpreter object is destroyed either explicitly
or implicitly, an implicit <em>DeleteCommand</em> happens on all its currently
registered commands.</p>
</dd>
</li>
<dt><strong><a name="item_setresult">SetResult (STRING)</a></strong>

<dd>
<p>Sets Tcl interpreter result to STRING.</p>
</dd>
</li>
<dt><strong><a name="item_appendresult">AppendResult (LIST)</a></strong>

<dd>
<p>Appends each element of LIST to Tcl's interpreter result object.</p>
</dd>
</li>
<dt><strong><a name="item_appendelement">AppendElement (STRING)</a></strong>

<dd>
<p>Appends STRING to Tcl interpreter result object as an extra Tcl list element.</p>
</dd>
</li>
<dt><strong><a name="item_resetresult">ResetResult ()</a></strong>

<dd>
<p>Resets Tcl interpreter result.</p>
</dd>
</li>
<dt><strong><a name="item_splitlist">SplitList (STRING)</a></strong>

<dd>
<p>Splits STRING as a Tcl list. Returns a Perl list or the empty list if
there was an error (i.e. STRING was not a properly formed Tcl list).
In the latter case, the error message is left in Tcl's interpreter
result object.</p>
</dd>
</li>
<dt><strong><a name="item_setvar">SetVar (VARNAME, VALUE, FLAGS)</a></strong>

<dd>
<p>The FLAGS field is optional. Sets Tcl variable VARNAME in the
interpreter to VALUE. The FLAGS argument is the usual Tcl one and
can be a bitwise OR of the constants Tcl::GLOBAL_ONLY,
Tcl::LEAVE_ERR_MSG, Tcl::APPEND_VALUE, Tcl::LIST_ELEMENT.</p>
</dd>
</li>
<dt><strong><a name="item_setvar2">SetVar2 (VARNAME1, VARNAME2, VALUE, FLAGS)</a></strong>

<dd>
<p>Sets the element <code>VARNAME1(VARNAME2)</code> of a Tcl array to VALUE. The optional
argument FLAGS behaves as in <em>SetVar</em> above.</p>
</dd>
</li>
<dt><strong><a name="item_getvar">GetVar (VARNAME, FLAGS)</a></strong>

<dd>
<p>Returns the value of Tcl variable VARNAME. The optional argument FLAGS
behaves as in <em>SetVar</em> above.</p>
</dd>
</li>
<dt><strong><a name="item_getvar2">GetVar2 (VARNAME1, VARNAME2, FLAGS)</a></strong>

<dd>
<p>Returns the value of the element <code>VARNAME1(VARNAME2)</code> of a Tcl array.
The optional argument FLAGS behaves as in <em>SetVar</em> above.</p>
</dd>
</li>
<dt><strong><a name="item_unsetvar">UnsetVar (VARNAME, FLAGS)</a></strong>

<dd>
<p>Unsets Tcl variable VARNAME. The optional argument FLAGS
behaves as in <em>SetVar</em> above.</p>
</dd>
</li>
<dt><strong><a name="item_unsetvar2">UnsetVar2 (VARNAME1, VARNAME2, FLAGS)</a></strong>

<dd>
<p>Unsets the element <code>VARNAME1(VARNAME2)</code> of a Tcl array.
The optional argument FLAGS behaves as in <em>SetVar</em> above.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="linking_perl_and_tcl_variables">Linking Perl and Tcl variables</a></h2>
<p>You can <em>tie</em> a Perl variable (scalar or hash) into class Tcl::Var
so that changes to a Tcl variable automatically &quot;change&quot; the value
of the Perl variable. In fact, as usual with Perl tied variables,
its current value is just fetched from the Tcl variable when needed
and setting the Perl variable triggers the setting of the Tcl variable.</p>
<p>To tie a Perl scalar <em>$scalar</em> to the Tcl variable <em>tclscalar</em> in
interpreter <em>$interp</em> with optional flags <em>$flags</em> (see <em>SetVar</em>
above), use</p>
<pre>
        <span class="keyword">tie</span> <span class="variable">$scalar</span><span class="operator">,</span> <span class="variable">Tcl::Var</span><span class="operator">,</span> <span class="variable">$interp</span><span class="operator">,</span> <span class="string">"tclscalar"</span><span class="operator">,</span> <span class="variable">$flags</span><span class="operator">;</span>
</pre>
<p>Omit the <em>$flags</em> argument if not wanted.</p>
<p>To tie a Perl hash <em>%hash</em> to the Tcl array variable <em>array</em> in
interpreter <em>$interp</em> with optional flags <em>$flags</em>
(see <em>SetVar</em> above), use</p>
<pre>
        <span class="keyword">tie</span> <span class="variable">%hash</span><span class="operator">,</span> <span class="variable">Tcl::Var</span><span class="operator">,</span> <span class="variable">$interp</span><span class="operator">,</span> <span class="string">"array"</span><span class="operator">,</span> <span class="variable">$flags</span><span class="operator">;</span>
</pre>
<p>Omit the <em>$flags</em> argument if not wanted. Any alteration to Perl
variable <em>$hash{&quot;key&quot;}</em> affects the Tcl variable <em>array(key)</em>
and <em>vice versa</em>.</p>
<p>
</p>
<h2><a name="accessing_perl_from_within_tcl">Accessing Perl from within Tcl</a></h2>
<p>After creation of Tcl interpreter, in addition to evaluation of Tcl/Tk
commands within Perl, other way round also instantiated. Within a special
namespace <code> ::perl </code> following objects are created:</p>
<pre>
   ::perl::Eval</pre>
<p>So it is possible to use Perl objects from within Tcl.</p>
<p>
</p>
<h2><a name="moving_tcl_tk_around_with_tcl_pm">Moving Tcl/Tk around with Tcl.pm</a></h2>
<p>NOTE: explanations below is for developers managing Tcl/Tk installations
itself, users should skip this section.</p>
<p>In order to create Tcl/Tk application with this module, you need to make
sure that Tcl/Tk is available within visibility of this module. There are
many ways to achieve this, varying on ease of starting things up and
providing flexible moveable archived files.</p>
<p>Following list enumerates them, in order of increased possibility to change
location.</p>
<ul>
<li><strong><a name="item_first_method">First method</a></strong>

<p>Install Tcl/Tk first, then install Perl module Tcl, so installed Tcl/Tk will
be used. This is most normal approach, and no care of Tcl/Tk distribution is
taken on Perl side (this is done on Tcl/Tk side)</p>
</li>
<li><strong><a name="item_second_method">Second method</a></strong>

<p>Copy installed Tcl/Tk binaries to some location, then install Perl module Tcl
with a special action to make Tcl.pm know of this location. This approach
makes sure that only chosen Tcl installation is used.</p>
</li>
<li><strong><a name="item_third_method">Third method</a></strong>

<p>During compiling Tcl Perl module, Tcl/Tk could be statically linked into
module's shared library and all other files zipped into a single archive, so
each file extracted when needed.</p>
</li>
</ul>
<p>Some global variables within $Tcl::config:: namespace are used to make
such installations possible.</p>
<p>
</p>
<h3><a name="first_method">First method</a></h3>
<p>
</p>
<h3><a name="second_method">Second method</a></h3>
<p>To use second approach, desired set of Tcl/Tk binaries should be prepared
in a single directory. Mostly these files could be files from existing Tcl/Tk
installation.</p>
<p>Use <code>create-moveable-dist.pl</code> script to create proper configuration this way.</p>
<p>From inmplementation side of view, following things are done in this way:</p>
<ul>
<li><strong><a name="item_entire_tcl_2ftk_directory_is_copied_into_blib_2fli">Entire Tcl/Tk directory is copied into <code>blib/lib</code></a></strong>

<li><strong><a name="item_tcl_2ecfg_file_is_created_at_the_same_dir_where_tc">Tcl.cfg file is created at the same dir where Tcl.pm is placed; this
file contain some configuration and a code to initially load Tcl shared library.</a></strong>

</ul>
<p>
</p>
<h3><a name="third_method">Third method</a></h3>
<p>To link Tcl/Tk binaries, prepare their libraries and then instruct Makefile.PL
to use these libraries in a link stage.
(TODO provide better detailed description)</p>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Malcolm Beattie, <a href="mailto:mbeattie@sable.ox.ac.uk,">mbeattie@sable.ox.ac.uk,</a> 23 Oct 1994.
Vadim Konovalov, <a href="mailto:vkon@cpan.org,">vkon@cpan.org,</a> 19 May 2003.
Jeff Hobbs, jeff (a) activestate . com, 22 Mar 2004.
Gisle Aas, gisle (a) activestate . com, 14 Apr 2004.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.</p>
<p>See <a href="http://www.perl.com/perl/misc/Artistic.html">http://www.perl.com/perl/misc/Artistic.html</a></p>

</body>

</html>

⌨️ 快捷键说明

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