Support class methods
Closed / Out of Date1865198fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 3 years ago
Descriptionplain2008-01-06 17:27:02
There is one function, which is needed in itcl-ng but I think it should be in the TclOO Source code: calling a class method without an object context. This is mostly used for the equivalent of the C++ static class method invocation, which in itcl is called a "class proc". As it mostly does the same as TclOO's InvokeProcedure method and it uses TclOO internal stuff, I think it should be added to TclOO source code. A prototype implementation, which is used at the moment in itcl-ng is in the attachment.
wiedeplain2008-01-07 00:27:02
File Added - 261064: classmethodinvoke.c
wiedeplain2008-01-07 01:29:54
File Added - 261069: classmethodinvoke2.c Logged In: YES user_id=558925 Originator: YES I have added a slightly modified version of the function, which allows me to use it on a second place for itcl ensembles (which are nevertheless mostly running as namespace ensembles already). File Added: classmethodinvoke2.c
dkf Ticket [1865198fff]: 1 change
[History diff]2008-01-14 22:14:46
dkfplain2008-05-08 22:22:25
Logged In: YES user_id=79902 Originator: NO Reducing priority; this can be addressed after the TIP#257 vote.
dkfplain2009-07-12 22:12:19
How does a class method work? Is it just like invoking a method on the class object?
If so, can do it like this:
oo::class create Foo {
constructor {} {
interp alias {} [namespace current]::Foo->my {} [info object namespace Foo]::my
}
forward foo Foo->my foo
self method foo {args} {
puts "[self], $args"
}
}
Arguably there's a need for a neater way to do this so that more of the machinery is hidden, but this will work. (Note that this is a real class method; none of the object-specific state variables or methods are visible at all. The method can be invoked just the same on the class object.)
dkf Ticket [1865198fff]: 2 changes
[History diff]2009-07-12 22:13:04
dkf Ticket [1865198fff]: 1 change
[History diff]2009-07-13 01:18:06
dkfplain2009-08-02 22:20:42
File Added - 337678: class.tcl
dkfplain2009-08-02 22:22:13
I've attached a Tcl script that allows the declaration of class methods, and which also supports class variables.
dkfmarkdown2024-05-23 14:23:01
Tcl 8.7/9.0 have the solution to this: the classmethod definition command in TIP #478.
Log in (anonymous is fine) to add a comment.
Attachments:
- class.tcl [download] added by dkf on 2009-08-02 22:20:41. [details]
- classmethodinvoke2.c [download] added by wiede on 2008-01-07 01:29:54. [details]
- classmethodinvoke.c [download] added by wiede on 2008-01-07 00:27:02. [details]