02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Tornado</strong> 2.0<br />

User’s Guide<br />

Tcl: Calling Target Routines<br />

The shParse utility allows you to embed calls to the C interpreter in Tcl<br />

expressions; the most frequent application is to call a single target routine, with the<br />

arguments specified (and perhaps capture the result). For example, the following<br />

sends a logging message to your VxWorks target console:<br />

tcl> shParse {logMsg("Greetings from Tcl!\n")}<br />

32<br />

You can also use shParse to call WindSh commands more conveniently from the<br />

Tcl interpreter, rather than using their wtxtcl building blocks. For example, the<br />

following is a convenient way to spawn a task from Tcl, using the C-interpreter<br />

command sp( ), if you do not remember the underlying wtxtcl command:<br />

tcl> shParse {sp appTaskBegin}<br />

task spawned: id = 25e388, name = u1<br />

0<br />

Tcl: Passing Values to Target Routines<br />

Because shParse accepts a single, ordinary Tcl string as its argument, you can pass<br />

values from the Tcl interpreter to C subroutine calls simply by using Tcl facilities to<br />

concatenate the appropriate values into a C expression.<br />

For example, a more realistic way of calling logMsg( )from the Tcl interpreter<br />

would be to pass as its argument the value of a Tcl variable rather than a literal<br />

string. The following example evaluates a Tcl variable tclLog and inserts its value<br />

(with a newline appended) as the logMsg( ) argument:<br />

tcl> shParse "logMsg(\"$tclLog\\n\")"<br />

32<br />

5.7.2 Tcl: Calling Under C Control<br />

To dip quickly into Tcl and return immediately to the C interpreter, you can type a<br />

single line of Tcl prefixed with the ? character (rather than using ? by itself to toggle<br />

into Tcl mode). For example:<br />

-> ?set test wonder; puts "This is a $test."<br />

This is a wonder.<br />

-><br />

200

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!