Modularized sdx components (was: RE: [Starkit] Data Files in Starkit)

Brian Theado brian_theado at yahoo.com
Sat Jan 1 11:11:57 CET 2005


Jean-Claude Wippler wrote:

> Jeff Godfrey wrote:
>
>> "Brian Theado" <brian_theado at yahoo.com>
>>
>>> I would love it if sdx components were available
in
>>> some form as Tcl  packages/procedures.
>>
>>
>> As would I...
>
>
> Me three.
>
> It has always struck me as most unfortunate that
scripts called with 
> arguments are coded very differently from Tcl
commands.  Why the argv 
> vs. args dichotomy?  Couldn't argv remain a global,
but the main app 
> somehow get called as a normal Tcl proc, using args
if it wants to 
> accept variable argument lists, like everywhere
else?  And what about 
> switch on first arg versus (in 8.5) ensembles or
major/minor command 
> sets?
>
> Couldn't / shouldn't this be solved in a very
general way, so all apps 
> can be made to act as either command-line callable
or as 
> source-then-call-as-Tcl-Proc sequences? 

[snip]

Using slave interpreters it is pretty easy to wrap
applications to give 
the illusion of making an application with subcommands
into a procedure 
with subcommands.  In particular for sdx the following
can be easily 
achieved with no changes to the sdx application code:

source sdx.kit
package require sdx
sdx::sdx wrap blah.kit
sdx::sdx lsk blah.kit

This works by creating a slave interpreter and setting
up argv, argc, 
::argv0 correctly for each call to sdx::sdx.  Here are
the specific changes:

1) change main.tcl in sdx to allow it to be sourced
without calling any 
functionality:
package require starkit
if {[starkit::startup] != "sourced"} {
    package require app-sdx
}

2) Create an sdx package using the following code:
namespace eval sdx {
    namespace export sdx
    proc sdx args {
        set s [interp create [namespace current]::s]
        $s eval {
            proc exit {{returnCode 0}} {
                if {$returnCode} {
                    error "sdx slave interpreter
exited abnormally: 
$returnCode"
                } else {
                    return $returnCode
                }
            }
        }
        $s eval set argv [list $args]
        $s eval set argc [llength $args]
        $s eval set argv0 $::argv0
        $s eval set auto_path [list $::auto_path]
        set error [catch {$s eval package require
app-sdx} return]
        if { $error } { set code error } { set code ok
}
        interp delete $s
        return -code $code $return
        }
    }
package provide sdx 1.0


Any chance of adding this to sdx?

Brian


		
__________________________________ 
Do you Yahoo!? 
Dress up your holiday email, Hollywood style. Learn more. 
http://celebrity.mail.yahoo.com


More information about the Starkit mailing list