3

是否有列出 TCL 中所有源文件的命令?

例如 - 我来源a.tcl, b.tcl,c.tcltest.tcl文件中。是否有 TCL 命令来查看源文件?

4

1 回答 1

7

No, but you can override the source command itself to keep track of the source'd files somewhere, like this:

rename source __real_source
proc source args {
    global sourced
    lappend sourced $args
    uplevel 1 [linsert $args 0 __real_source]
}

Update: expanding on the Donal's comment regarding the fragility of the source command there's how one could setup an execution trace:

proc register_sourced {cmd args} {
  global sourced
  lappend sourced [lindex $cmd end]
}
trace add execution source leave register_sourced
于 2012-04-10T10:30:01.510 回答