Introspection

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 14.  Namespaces


The info commands operation returns all the commands that are currently visible. It is described in more detail on page 179. You can limit the information returned with a string match pattern. You can also include a namespace specifier in the pattern to see what is visible in a namespace. Remember that global commands and imported commands are visible, so info commands returns more than just what is defined by the namespace. Example 14-5 uses namespace origin, which returns the original name of imported commands, to sort out the commands that are really defined in a namespace:

Example 14-5 Listing commands defined by a namespace.
 proc Namespace_List {{namespace {}}} {    if {[string length $namespace] == 0} {       # Determine the namespace of our caller       set namespace [uplevel {namespace current}]    }    set result {}    foreach cmd [info commands ${namespace}::*] {       if {[namespace origin $cmd] == $cmd} {          lappend result $cmd       }    }    return [lsort $result] } 

       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net