Index: TODO =================================================================== diff -u -rbf8a6fa213583971dfe9eafabaaecd8166c4343d -re67f194e31b8e0fb4f1312a3257088a94e598b0d --- TODO (.../TODO) (revision bf8a6fa213583971dfe9eafabaaecd8166c4343d) +++ TODO (.../TODO) (revision e67f194e31b8e0fb4f1312a3257088a94e598b0d) @@ -3687,8 +3687,18 @@ register_system_slots ""' fails on aolserver * bump version number to 2.0b1 +- nsf.c: extended "new": + * nonpos-arg "-childof" accepts now a namespace + (required an object before). Thefore, one can + use now "... new -childof [namespace current]", + even when the current namespace is not an object +- nx.tcl: simplified ::nx::ScopedNew to ::nx::NsScopedNew: + before it was necessary to create a new volatile class for every + invocaton of contains. +- extended regression test + TODO: - warnings for "numeric" names for args and nonpos-args? Index: library/nx/nx.tcl =================================================================== diff -u -rbf8a6fa213583971dfe9eafabaaecd8166c4343d -re67f194e31b8e0fb4f1312a3257088a94e598b0d --- library/nx/nx.tcl (.../nx.tcl) (revision bf8a6fa213583971dfe9eafabaaecd8166c4343d) +++ library/nx/nx.tcl (.../nx.tcl) (revision e67f194e31b8e0fb4f1312a3257088a94e598b0d) @@ -1859,23 +1859,15 @@ ###################################################################### # Create a mixin class to overload method "new" such it does not - # allocate new objects in ::nx::*, but in the specified object - # (without syntactic overhead). + # allocate new objects in ::nx::*, but in the current namespace ###################################################################### - Class create ::nx::ScopedNew -superclass ::nx::Class { - - :property {withclass ::nx::Object} - :property container - - :protected method init {} { - :public method new {-childof args} { - ::nsf::var::import [::nsf::current class] {container object} withclass - if {![::nsf::object::exists $object]} { - $withclass create $object - } - ::nsf::next [list -childof $object {*}$args] - } + Class create ::nx::NsScopedNew { + :public method new {-childof args} { + if {![info exists childof]} { + set childof [uplevel {namespace current}] + } + ::nsf::next [list -childof $childof {*}$args] } } @@ -1895,23 +1887,39 @@ } { if {![info exists object]} {set object [::nsf::self]} if {![::nsf::object::exists $object]} {$class create $object} - # reused in XOTcl, no "require" there, so use nsf primitiva + # This method is reused in XOTcl which has e.g. no "require"; + # therefore use nsf primitiva. ::nsf::directdispatch $object ::nsf::methods::object::requirenamespace + if {$withnew} { - set m [ScopedNew new -container $object -withclass $class] - $m volatile - Class mixin add $m end + set m ::nx::NsScopedNew + # + # Check, if we need to add a mixin for "new": + # + set nxMl [Class ::nsf::methods::class::info::mixinclasses $m] + if {$nxMl eq ""} { + Class mixin add $m end + } # TODO: the following is not pretty; however, contains might # build xotcl and next objects. - if {[::nsf::is class ::xotcl::Class]} {::xotcl::Class instmixin add $m end} - #namespace eval $object $cmds - #::nsf::directdispatch [self] -frame method ::apply [list {} $cmds $object] + if {[::nsf::is class ::xotcl::Class]} { + set xotclMl [::xotcl::Class ::nsf::methods::class::info::mixinclasses $m] + if {$xotclMl eq ""} {::xotcl::Class instmixin add $m end} + } + # + # Evaluate the command + # ::apply [list {} $cmds $object] - Class mixin delete $m - if {[::nsf::is class ::xotcl::Class]} {::xotcl::Class instmixin delete $m} + # + # Remove the mixin for "new", if it was added before + # + if {$nxMl eq ""} { + Class mixin delete $m + } + if {[::nsf::is class ::xotcl::Class]} { + if {$xotclMl eq ""} {::xotcl::Class instmixin delete $m} + } } else { - #namespace eval $object $cmds - #::nsf::directdispatch [self] -frame method ::apply [list {} $cmds $object] ::apply [list {} $cmds $object] } } Index: tests/contains.test =================================================================== diff -u -r7d197d8e8a9ad6229c2aa8a11111118f5cab26b6 -re67f194e31b8e0fb4f1312a3257088a94e598b0d --- tests/contains.test (.../contains.test) (revision 7d197d8e8a9ad6229c2aa8a11111118f5cab26b6) +++ tests/contains.test (.../contains.test) (revision e67f194e31b8e0fb4f1312a3257088a94e598b0d) @@ -55,6 +55,11 @@ Tree create 1.3 -label 1.3 }] +set x [Tree create t -contains { + ? {Tree create branch} ::t::branch + ? {Tree new} ::t::__#1 +}] + # # Test resolving next without namespace import/path #