Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-05-23
14:23 • Closed ticket [1865198fff]: Support class methods plus 8 other changes artifact: e239ea5dc4 user: dkf
2009-08-02
22:22 • Ticket [1865198fff]: 4 changes artifact: f1c61e974d user: dkf
22:20 • Ticket [1865198fff]: 4 changes artifact: e8b64f38d1 user: dkf
22:20 • Add attachment class.tcl to ticket [1865198fff] artifact: 9cf504c9a8 user: dkf
2009-07-13
01:18 • Ticket [1865198fff] Support class methods status still Open with 1 other cha... artifact: 4332ea2489 user: dkf
2009-07-12
22:13 • Ticket [1865198fff]: 2 changes artifact: 5c7500c4b5 user: dkf
22:12 • Ticket [1865198fff]: 4 changes artifact: 3c55c57831 user: dkf
2008-05-08
22:22 • Ticket [1865198fff]: 5 changes artifact: 02814e15c3 user: dkf
2008-01-14
22:14 • Ticket [1865198fff]: 1 change artifact: 11baf1113c user: dkf
2008-01-07
01:29 • Ticket [1865198fff]: 4 changes artifact: 6181fe7bcc user: wiede
01:29 • Add attachment classmethodinvoke2.c to ticket [1865198fffffffff|1865198... artifact: cebb06b29d user: wiede
00:27 • Ticket [1865198fff] Additional class method invoking function in TclOO statu... artifact: 10b278c963 user: wiede
00:27 • Add attachment classmethodinvoke.c to ticket [1865198fffffffff|1865198f... artifact: 951b27bb14 user: wiede
2008-01-06
17:27 • New ticket [1865198fff] Additional class method invoking function in TclOO. artifact: 78be0444f3 user: wiede

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: