Index: library/nx/nx.tcl =================================================================== diff -u -r62dbdfdbe5604ced0d8eff5ee990e525bb931cec -r489b8b8e5f1ce1522121dcee270f18396c380071 --- library/nx/nx.tcl (.../nx.tcl) (revision 62dbdfdbe5604ced0d8eff5ee990e525bb931cec) +++ library/nx/nx.tcl (.../nx.tcl) (revision 489b8b8e5f1ce1522121dcee270f18396c380071) @@ -1244,7 +1244,8 @@ if {[info exists :initcmd]} { lappend options initcmd if {[info exists :default]} { - append initcmd "::nsf::var::set \[::nsf::self\] ${:name} ${:default};\n" + # append initcmd "[::nsf::self] setCheckedInstVar -nocomplain \[::nsf::self\] [list ${:default}]\n" + append initcmd "::nsf::var::set \[::nsf::self\] ${:name} [list ${:default}]\n" } append initcmd ${:initcmd} set :parameterSpec [list [:namedParameterSpec $prefix ${:name} $options] $initcmd] @@ -1548,15 +1549,24 @@ valuechangedcmd } - ::nx::VariableSlot public method setCheckedInstVar {-nocomplain:switch value} { - if {[::nsf::var::exists ${:domain} ${:name}] && !$nocomplain} { - error "object ${:domain} has already an instance variable named '${:name}'" + ::nx::VariableSlot public method setCheckedInstVar {-nocomplain:switch object value} { + + if {[::nsf::var::exists $object ${:name}] && !$nocomplain} { + error "object $object has already an instance variable named '${:name}'" } set options [:getParameterOptions -withMultiplicity true] - if {[llength $options] > 0} { + if {[llength $options]} { ::nsf::is -complain [join $options ,] $value } - ::nsf::var::set ${:domain} ${:name} ${:default} + + set traces [::nsf::directdispatch $object -frame object ::trace info variable ${:name}] + foreach trace $traces { + lassign $trace ops cmdPrefix + ::nsf::directdispatch $object -frame object ::trace remove variable ${:name} $ops $cmdPrefix + append restore "[list ::nsf::directdispatch $object -frame object ::trace add variable ${:name} $ops $cmdPrefix]\n" + } + ::nsf::var::set $object ${:name} ${:default} + if {[info exists restore]} { {*}$restore } } ::nx::VariableSlot protected method getParameterOptions { @@ -1657,7 +1667,7 @@ unset -nocomplain :parameterSpec :makeAccessor if {${:per-object} && [info exists :default]} { - :setCheckedInstVar -nocomplain=[info exists :nocomplain] ${:default} + :setCheckedInstVar -nocomplain=[info exists :nocomplain] ${:domain} ${:default} } if {[::nsf::is class ${:domain}]} { ::nsf::invalidateobjectparameter ${:domain} @@ -1862,7 +1872,7 @@ {*}[expr {[info exists defaultValue] ? [list $defaultValue] : ""}]] if {$nocomplain} {$slot eval {set :nocomplain 1}} - if {[info exists defaultValue]} {$slot setCheckedInstVar -nocomplain=$nocomplain $defaultValue} + if {[info exists defaultValue]} {$slot setCheckedInstVar -nocomplain=$nocomplain [self] $defaultValue} if {[$slot eval {info exists :settername}]} { set name [$slot settername] Index: tests/parameters.test =================================================================== diff -u -r364a9eda329acd7d20173a4165d71394d3061aae -r489b8b8e5f1ce1522121dcee270f18396c380071 --- tests/parameters.test (.../parameters.test) (revision 364a9eda329acd7d20173a4165d71394d3061aae) +++ tests/parameters.test (.../parameters.test) (revision 489b8b8e5f1ce1522121dcee270f18396c380071) @@ -1378,11 +1378,10 @@ } ? {o eval {info exists :a}} 1 - ? {o a} 1 + ? {o a} 0 ? {o a 1} 2 ? {o a} 2 ? {o a 2} 3 - # per-class: Class create Klass @@ -1403,13 +1402,7 @@ Klass property {a 0} { set :valuechangedcmd {::nsf::var::set $obj $var [expr [list [::nsf::var::set $obj $var] + 1]]} } - - # - # TODO: Right now, the per-object traces *do* fire upon setting the - # default value; the per-class traces won't ... this should be - # symmetric, either way ... - # - + Klass create k ? {k eval {info exists :a}} 1 ? {k a} 0; # should be 1, reflecting the corresponding per-object case above