Index: library/xotcl/library/xotcl2.tcl =================================================================== diff -u -r764405083cfd6152d6956674e54f3a77cf7e1dcd -r65e384fc5b5fa044c63075f03756da88d316249f --- library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 764405083cfd6152d6956674e54f3a77cf7e1dcd) +++ library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 65e384fc5b5fa044c63075f03756da88d316249f) @@ -79,25 +79,6 @@ namespace import ::nsf::method::alias ::nsf::is ::nsf::relation interp alias {} ::xotcl::next {} ::nsf::xotclnext - # - # create ::xotcl::MetaSlot for better compatibility with XOTcl 1 - # - ::nx::Class create ::xotcl::MetaSlot -superclass ::nx::MetaSlot { - :property parameter - :method init {} { - if {[info exists :parameter]} {my ::nsf::classes::xotcl::Class::parameter ${:parameter}} - next - } - # provide minimal compatibility - :public forward instproc %self public method - :public forward proc %self public class method - } - - # - # Create ::xotcl::Attribute for compatibility - # - ::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::nx::VariableSlot - proc ::xotcl::self {{arg ""}} { switch $arg { "" {uplevel ::nsf::self} @@ -930,6 +911,42 @@ proc myvar {var} {:requireNamespace; return [::xotcl::self]::$var} # + # create ::xotcl::MetaSlot for better compatibility with XOTcl 1 + # + ::nx::Class create ::xotcl::MetaSlot -superclass ::nx::MetaSlot { + :property parameter + :method init {} { + if {[info exists :parameter]} {my ::nsf::classes::xotcl::Class::parameter ${:parameter}} + next + } + # provide minimal compatibility + :public forward instproc %self public method + :public forward proc %self public class method + # + # As NX/XOTcl hybrids, all slot kinds would not inherit the + # unknown behaviour of ::xotcl::Class. Therefore, we provide it + # explicitly to slots for backward compatibility ... + # + :public alias unknown ::nsf::classes::xotcl::Class::unknown + } + + # + # Create ::xotcl::Attribute for compatibility + # + ::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::nx::VariableSlot { + :property multivalued { + :public method assign {object property value} { + set mClass [expr {$value?"0..n":"1..1"}] + $object incremental $value + $object multiplicity $mClass + } + :public method get {object property} { + return [$object eval [list :isMultivalued]] + } + } + } + + # # Provide a backward compatible version of ::xotcl::alias # ::nsf::proc ::xotcl::alias { Index: library/xotcl/tests/slottest.xotcl =================================================================== diff -u -r59e100d383b22ea1407f5e5c40e303f2c6bb9027 -r65e384fc5b5fa044c63075f03756da88d316249f --- library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision 59e100d383b22ea1407f5e5c40e303f2c6bb9027) +++ library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision 65e384fc5b5fa044c63075f03756da88d316249f) @@ -568,12 +568,62 @@ x move y ? {y a} 4 +::nx::Test case slots-compat +# +# Some tests covering the backward compatibility of NX/XOTcl2 hybrid +# slots to the XOTcl1 slot API (as extracted from the XOTcl language +# reference) +# + +# +# 1) old-style Attribute creation +# + +Class Window -slots { + Attribute scrollbar; # old style + Attribute create title; # new style +} + +? {lsort [Window info slots]} "::Window::slot::scrollbar ::Window::slot::title" + +# +# 2) Dropped/missing slot attributes: multivalued +# + +Class Person -slots { + Attribute name + Attribute salary -default 0 + Attribute projects -default {} -multivalued true +} + +? {lsort [Person info slots]} "::Person::slot::name ::Person::slot::projects ::Person::slot::salary" + +? {Person::slot::name multivalued} 0 +? {Person::slot::salary multivalued} 0 +? {Person::slot::projects multivalued} 1 + +Person p2 -name "John Doe" +? {p2 name} "John Doe" +? {p2 salary} "0" +? {p2 projects} [list] + +Project compatPrj -name XOTclCompat +p2 projects add ::compatPrj +p2 projects add some-other-value + +? {lsort [p2 projects]} "::compatPrj some-other-value" +p2 projects delete some-other-value +? {lsort [p2 projects]} "::compatPrj" + +? {catch {p2 name add BOOM!}} 1 +? {p2 name} "John Doe" + exit -#puts [Person array get __defaults] -#puts [Person serialize] -puts [Serializer all] -eval [Serializer all] + #puts [Person array get __defaults] + #puts [Person serialize] + puts [Serializer all] + eval [Serializer all] ? {p2 salary} 1009 ? {catch {p2 append salary b}} 1 @@ -686,6 +736,10 @@ puts stderr DONE-[p1 name]-[p1 age] p3 age 77 + + + + exit puts [XoXML asXML]