info level

What mean about the level number of "info level"?

 

proc arginfo {} {
   set proc [lindex [info level -1] 0]
   puts "/[[info level]/]"
   puts "info level 0 = /[[info level 0]/]"

   puts "info level 1 = /[[info level 1]/]"
   puts "info level 2 = /[[info level 2]/]" #test the number after info level mean

   #info level number中的number只可能是0,-1,1,2.

   #0代表當前procedure

   #-1代表調用目前procedure的procedure

   #1代表調用目前procedure的最高的那層procedure

   #2代表當前procedure所調用的procedure?還有疑問,如果當前procedure調用多個procedure呢?需作試驗
   puts "proc=$proc"
   set which [uplevel [list namespace which -command $proc]]
   puts "which=$which"
   puts "proc /[$which/]"
   set i -1
   foreach arg [info args $which] {
     incr i
     set value [uplevel [list set $arg]]
     puts "value=$value"
     if { [info default $which $arg def] } {
       puts "  arg/[$i/] /[$arg/] = /[$value/] default = /[$def/]"
     } else {
       puts "  arg/[$i/] /[$arg/] = /[$value/]"
     }
   }
}
proc test {foo {"bar baz" "BAR BAZ"}} {
   arginfo
}

 

結果:

% test a b
[2]
info level 0 = [arginfo]
info level 1 = [test a b]
info level 2 = [arginfo]
proc=test
which=::test
proc [::test]
value=a
  arg[0] [foo] = [a]
value=b
  arg[1] [bar baz] = [b] default = [BAR BAZ]

發佈了40 篇原創文章 · 獲贊 2 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章