Version 3 of inspect

Updated 2004-05-18 20:10:57

RS - Soon to come: a packlet of routines for introspecting your Tcl/Tk interpreter. Here's just a starter... (note also the documentation format used with, but not requiring, htext).

 namespace eval inspect {}

set docu(inspect::value) { This routine searches all global variables (scalar or array) for the specified value. Returns the list of variable names whose value matches. }

 proc inspect::value value {
    set res {}
    foreach i [info globals] {
        upvar #0 $i name 
        if [array exists name] {
            foreach j [array names name] {
               if [string equal $name($j)$value] {
                  lappend res ${i}($j)
               }
        } elseif [string equal $name $value] {
            lappend res $i
        }
    }
 }

LV have you ever seen tkinspect - lots of neat features relating to introspection...


See also the updated version of tkinspect: TixInspect


RS admits he never looked at tkinspect, and even less at Tix at all... and that the promise in the first sentence was never kept... but anyway, here's another little inspection tool that searches all defined procs for a given string:

 proc xref string {
    set res {}
    foreach proc [info procs] {
        if {[string first $string [info body $proc]]>=0} {lappend res $proc}
    }
    set res
 }

Arts and crafts of Tcl-Tk programming