# -*- Tcl -*- package require nx package require nx::test Test parameter count 10 Test case method-require { # # A few method-provides # # Some provides could be in e.g. nx.tcl, some could be loaded via # package require. We could as well think about an auto-indexer # producing these.... # nsf::method::provide append {::nsf::method::alias append -frame object ::append} nsf::method::provide lappend {::nsf::method::alias lappend -frame object ::lappend} nsf::method::provide set {::nsf::method::alias set -frame object ::set} nsf::method::provide tcl::set {::nsf::method::alias set -frame object ::set} nsf::method::provide exists {::nsf::method::alias exists ::nsf::methods::object::exists} nsf::method::provide foo {::nsf::method::create foo {x y} {return x=$x,y=$y}} nsf::method::provide x {::nsf::mixin ::MIX} { # here could be as well a package require, etc. ::nx::Class create ::MIX {:public method x {} {return x}} } # # Lets try it out: # nx::Class create C { :require method set :require method exists # required names can be different from registered names; if there # are multiple set methods, we could point to the right one :require method tcl::set # object methods: :require class-object method lappend # a scripted method :require class-object method foo :require class-object method x # looks as well ok: :require namespace } C create c1 ? {c1 set x 100} 100 ? {c1 exists x} 1 ? {C lappend some_list e1 e2} "e1 e2" ? {C foo 1 2} x=1,y=2 ? {C x} x } Test case parent-require { ::nx::Class public class-object method __unknown {name} { #puts stderr "***** __unknown called with <$name>" ::nx::Object create $name } nx::Class create C ? {C create ::o::o} "::o::o" ? {::o info class} "::nx::Object" ? {::o::o info class} "::C" ? {::nx::Object create ::a::b} "::a::b" ? {::a info class} "::nx::Object" ? {::a::b info class} "::nx::Object" ? {C create ::1::2::3::4} "::1::2::3::4" ? {::1 info class} "::nx::Object" ? {::1::2 info class} "::nx::Object" ? {::1::2::3 info class} "::nx::Object" ? {::1::2::3::4 info class} "::C" } # # Test what happens if a class-specific method is registered and # called on an object. # Test case method-require-scope { nx::Object create o ::nsf::method::require o alloc ? {o alloc x} {expected Class but got "::o"} }