Index: library/nx/class-method.tcl =================================================================== diff -u -r377258585e6d0715ad1da6430c833f6f346326f7 -r471c9589c601e576f2bc5f3e2dd4c554a0ceee1c --- library/nx/class-method.tcl (.../class-method.tcl) (revision 377258585e6d0715ad1da6430c833f6f346326f7) +++ library/nx/class-method.tcl (.../class-method.tcl) (revision 471c9589c601e576f2bc5f3e2dd4c554a0ceee1c) @@ -1,74 +1,118 @@ package provide nx::class-method 1.0 +# +# Provide a convenience layer to class methods/variables by using +# "class method" rather than "object method". This reflects the naming +# conventions of NX 2.0b4 and earlier. By using this package, one can +# use instead of +# +# nx::Class create C { +# :public object method foo args {....} +# :object property p:integer +# :object mixin add M +# #... +# puts [:info object methods] +# } +# +# a terminology closer to text book vocabulary +# +# package require nx::class-method +# +# nx::Object create o { +# :public class method foo args {....} +# :class property p:integer +# :class mixin add M +# #... +# puts [:class info methods] +# } +# +# Note that for object specific methods of object, have still to be +# defined via "object method" etc. (see also package +# nx::plain-object-method). +# + +# +# make "class" an accepted method defining method +# namespace eval ::nsf { array set ::nsf::methodDefiningMethod { class 1 } } namespace eval ::nx { - nx::Class eval { - :public alias "class method" ::nx::Object::slot::__object::method - - :public alias "class alias" ::nx::Object::slot::__object::alias - :public alias "class forward" ::nx::Object::slot::__object::forward - #:public method "class forward" args { - # puts stderr "CLASS CMD: [self] [current method] [current args]" - # :public object forward {*}$args - #} - - :public alias "class info" ::nx::Object::slot::__info - - :public method "class filter" args { - set what filter - switch [llength $args] { - 0 {return [::nsf::relation [::nsf::self] object-$what]} - 1 {return [::nsf::relation [::nsf::self] object-$what {*}$args]} - default {return [::nx::Object::slot::$what [lindex $args 0] \ - [::nsf::self] object-$what \ - {*}[lrange $args 1 end]] + # + # Define a method to allow configuration for tracing of the + # convenience methods. Use + # + # nx::configure class-method-warning on|off + # + # for activation/deactivation of tracing. This might be + # useful for porting legacy NX programs or for testing + # default-configuration compliance. + # + nx::configure public object method class-method-warning {onoff:boolean,optional} { + if {[info exists onoff]} { + set :class-method-warning $onoff + } else { + if {[info exists :class-method-warning]} { + if {${:class-method-warning}} { + uplevel {::nsf::log warn "class method: [self] [current method] [current args]"} } } } - :public method "class mixin" args { - set what mixin - switch [llength $args] { - 0 {return [::nsf::relation [::nsf::self] object-$what]} - 1 {return [::nsf::relation [::nsf::self] object-$what {*}$args]} - default {return [::nx::Object::slot::$what [lindex $args 0] \ - [::nsf::self] object-$what \ - {*}[lrange $args 1 end]] - } - } - } - :public alias "class filterguard" ::nsf::methods::object::filterguard - :public alias "class mixinguard" ::nsf::methods::object::mixinguard - } - # - # provide aliases for "class property" and "class variable" - # - ::nx::Class eval { - :alias "class property" ::nsf::classes::nx::Object::property - :alias "class variable" ::nsf::classes::nx::Object::variable - } - # - # provide aliases for "class delete" - # - ::nx::Class eval { - :alias "class delete property" ::nx::Object::slot::__delete::property - :alias "class delete variable" ::nx::Object::slot::__delete::variable - :alias "class delete method" ::nx::Object::slot::__delete::method + nx::Class eval { + + # + # Definitions redirected to "object" + # + foreach m { + alias + filter + forward + method + mixin + property + variable + } { + :public method "class $m" {args} { + nx::configure class-method-warning + :object [current method] {*}[current args] + } + } + + # + # info subcommands + # + foreach m { + method methods slots variables + "filter guards" "filter methods" + "mixin guards" "mixin classes" + } { + :public method "class info $m" {args} [subst -nocommands { + nx::configure class-method-warning + :info object $m {*}[current args] + }] + } } # - # info redirector + # Deletions # - ::nx::Class eval { - :alias "class info" ::nx::Object::slot::__info + foreach m { + property + variable + method + } { + nx::Class public method "class delete $m" {args} { + nx::configure class-method-warning + :delete object [current method] {*}[current args] + } } + ###################################################################### # Provide method "require" ###################################################################### @@ -77,13 +121,15 @@ # method require, base cases # :method "require class method" {methodName} { + nx::configure class-method-warning ::nsf::method::require [::nsf::self] $methodName 1 return [:info lookup method $methodName] } # # method require, public explicitly # :method "require public class method" {methodName} { + nx::configure class-method-warning set result [:require class method $methodName] ::nsf::method::property [self] $result call-protected false return $result @@ -92,6 +138,7 @@ # method require, protected explicitly # :method "require protected class method" {methodName} { + nx::configure class-method-warning set result [:require class method $methodName] ::nsf::method::property [self] $result call-protected true return $result @@ -100,6 +147,7 @@ # method require, private explicitly # :method "require private class method" {methodName} { + nx::configure class-method-warning set result [:require class method $methodName] ::nsf::method::property [self] $result call-private true return $result