Overview
Context
Changes
Deleted build/kits/app/lib/defer/defer.tcl version [0d30bb1082].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
namespace eval ::defer {
namespace export defer
variable idVar "<defer>\n<trace variable>"
}
proc ::defer::with {args} {
if {[llength $args] == 1} {
set varlist [list]
set code [lindex $args 0]
} elseif {[llength $args] == 2} {
set varlist [lindex $args 0]
set code [lindex $args 1]
} else {
return -code error "wrong # args: defer::with ?varlist? script"
}
if {[info level] == 1} {
set global true
} else {
set global false
}
# We can't reliably handle cleanup from the global scope, don't let people
# register ineffective handlers for now
if {$global} {
return -code error "defer may not be used from the global scope"
}
# Generate an ID to un-defer if requested
set id [clock clicks]
for {set i 0} {$i < 5} {incr i} {
append id [expr rand()]
}
# If a list of variable names has been supplied, slurp up their values
# and add the appropriate script to set those variables in the lambda
## Generate a list of commands to create the variables
foreach var $varlist {
if {![uplevel 1 [list info exists $var]]} {
continue
}
if {[uplevel 1 [list array exists $var]]} {
set val [uplevel 1 [list array get $var]]
lappend codeSetVars [list unset -nocomplain $var]
lappend codeSetVars [list array set $var $val]
} else {
set val [uplevel 1 [list set $var]]
lappend codeSetVars [list set $var $val]
}
}
## Format the above commands in the structure of a Tcl command
if {[info exists codeSetVars]} {
set codeSetVars [join $codeSetVars "; "]
set code "${codeSetVars}; ${code}"
}
## Unset the "args" variable, which is just an artifact of the lambda
set code "# ${id}\nunset args; ${code}"
# Register our interest in a variable to monitor for it to disappear
uplevel 1 [list trace add variable $::defer::idVar unset [list apply [list args $code]]]
return $id
}
proc ::defer::defer {args} {
set code $args
tailcall ::defer::with $code
}
proc ::defer::autowith {script} {
tailcall ::defer::with [uplevel 1 {info vars}] $script
}
proc ::defer::cancel {args} {
set idList $args
set traces [uplevel 1 [list trace info variable $::defer::idVar]]
foreach trace $traces {
set action [lindex $trace 0]
set code [lindex $trace 1]
foreach id $idList {
if {[string match "*# $id*" $code]} {
uplevel 1 [list trace remove variable $::defer::idVar $action $code]
}
}
}
}
package provide defer 1
|
Deleted build/kits/app/lib/defer/pkgIndex.tcl version [27b031db4c].
1
|
|
-
|
package ifneeded defer 1 [list source [file join $dir defer.tcl]]
|
Added vendor/tcl-packages/defer/defer.tcl version [0d30bb1082].