Neat scripting trick... 
Author Message
 Neat scripting trick...

I've been writing Tcl scripts to support Java development.  I
have written a number of command-line tools to process Java
source files in various ways and also wanted to run the procs
that implement those tools from a central "launcher" GUI.
My problem was, how to source the procs of a command line
tool into the GUI without actually executing the tool.  I found
a neat trick to solve this problem: it allows one script to be
both a library of procs and a stand-alone program.  It's so
neat (and useful) I thought I'd share it with the Tcl user
community...

Basically, you define your procs and globals in the usual
way.  Then, you enclose the main body of your script (ie:
the commands parse command-line arguments and calls the
procs defined in the rest of the file) in the following if
statement that only executes the body if the script being
sourced and the main program are one and the same:

if {[string compare [info script] $argv0] == 0} {
        # ... body of script goes here

Quote:
}

Marvelously simple!

Cheers,
        Nat.

--
+------------------------------------------+---------------------+
| Name:   Nat Pryce MEng ACGI              | Dept. of Computing, |

| Tel:    +44 (0)171 594 8394              | 180 Queen's Gate,   |
| Fax:    +44 (0)171 581 8024              | London SW7 2BZ,     |
| WWW:     http://www.*-*-*.com/ ~np2 | United Kingdom      |
+------------------------------------------+---------------------+



Tue, 26 Dec 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Neat Net Tricks

2. A Neat ALC Trick

3. YANVT: yet another neat vi trick

4. Programming BIOS Flash Roms -- Neat trick!

5. Neat Fortran/Numerical tricks

6. REXX BEAUTIES: Post those little, neat, handy rexx scripts

7. Script SFNode Syntax Trick -- Dot Drilling Legal?

8. script portability trick

9. Neat trick: `n' listboxes scrolled with one scrollbar

10. Neat recursive menu program written in awk

11. Making Code Neat

12. Squeak is neat, but in hangs...

 

 
Powered by phpBB® Forum Software