Friday, February 25, 2022

Using Tcl to trace changes to array variables

 
The Tcl trace command can be used to respond to changes to variables occur, these changes are array, read, write and unset. 


When one of these events occurs, a sub-script is execute and a number of values passed to it. In the case of an array operation, these are the array name, the member, and the operation.

Following this it is then possible, with a bit of string splicing, to obtain the value of the value of the changed array member.

Example:


proc AAA {args} {
    lassign $args a b c
    puts [set ${a}($b)]    
    }


trace add variable ::conze::editor::block write AAA
set ::conze::editor::block(::gnocl::_WID26_,start) 5


No comments: