Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Challange !! How to override one sub command only

Status
Not open for further replies.

amirvosko

Programmer
Apr 19, 2005
7
US
Hello all,

Some commands names in TCL are composed from several words for example "info tclversion" "info script" and "info body" . I need to override one of these commands ( "info script" ) but to keep the rest of them alive.

Unfortunately, overriding the command "info script" either with Tcl_CreateObjCommand() or by definining proc "info script" ... override all the "info *" commands . It seems for TCL the command name is "info" and the rest are considered 'sub commands' thus by overriding "info script" I actualy override the entire "info" command with all its sub commands .

Does anyone have a way to override only one sub command and keeping the rest of them ???

Thanks for your help !
 
No. I don't know how. But why "override"? Why not just define a new function that does what you want?

_________________
Bob Rashkin
 
That's the workaround I'll probably go for. Overriding the exiting command is still better as users and existing scripts do need to be aware of that. By creating new command we'll have to update scripts and users and in response get complains that our implementation is not compatible with TCL .

 
Hi! Why don't you try something like this:

Code:
rename info info_original

proc info args {
    switch [lindex $args 0] {
        script {
            # your script implementation
        }
        body {
            # your body implementation
        }
        default {
            return [uplevel info_original $args]
        }
    }
}

This does not really "override" the subcommands, but it kind of simulates the behaviour you want.

Regards,
LF28



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top