Skip to content
Tcl Source Code View Ticket
Login

View Ticket

trace not working in global, and upvar cases

Closed / Fixed217948ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:46:29
OriginalBugID: 3917 Bug
Version: 8.2.1
SubmitDate: '1999-12-21'
LastModified: '2000-01-20'
Severity: MED
Status: Closed
Submitter: techsupp
ChangedBy: ericm
RelatedBugIDs: 1433
OS: Linux
OSVersion: 2.0.37
Machine: 166 AMD 128M ram 19 Gig HD.
FixedDate: '2000-10-25'
ClosedDate: '2000-01-20'


Name:
Kenn Persinger

Comments:
Tcl is the greatest scripting language i've found.. I program in perl at work since its the company standard, but when i go home to program for fun, tcl is what i use. you guys have done a wonderful job.

ReproducibleScript:
#this sets up the array

################################
# Sets Up the Cursor Handling  #
################################
proc InitPointerArray {} {
    uplevel #0 {
        array set Pointer "x {} y {}"
        trace variable Pointer rwu SetPointerXY
    }
}

# This one sets the values.
# each time its called, it updates the values.
proc SetPointerXY {args} {
    uplevel #0 {
        set Pointer(x) [winfo pointerx .] 
        set Pointer(y) [winfo pointery .]
    }
}

#This GetVar fails to execute the trace. ie: GetVar1 Pointer(x)
proc GetVar1 {varname} {
    upvar #0 $varname myvar
    return $myvar
}

# This one also Fails. ie: GetVar2 Pointer(x)
proc GetVar2 {varname} {
    global $varname
    return $varname
}

# This GetVar works perfect
proc GetVar3 {varname} {
 return [uplevel #0 set $varname]
}

InitPointerAraay
SetPointerXY ""

puts "This one fails"
GetVar1 Pointer(x)
puts "This one also fails"
GetVar2 Pointer(x)
puts "This one is correct"
GetVar3 Pointer(x)

ObservedBehavior:
I have an array w/ two values, the X and Y of the mouse pointer

 i've set a trace on them so that anytime they are read, the trace executes, and updates the value (nicely, before the read)

 i created a proc called GetVar <varname> and use it to allow a child interp to grab values from the parent. i've found, if i use upvar, and try to get one of those variables, the trace is never triggered.
 i've also tryed using 'global' rather than upvar, and IT doesn't work either. i finally fell back on: return [uplevel #0 set 
 $varname] which DOES trigger the trace, but is in my opinion, a bad way to do it.
welch Closed ticket [217948ffff]. [History diff]2000-10-26 08:10:55
Log in (anonymous is fine) to add a comment.