Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Function to get class name of object

Closed / Fixed3ff0e9c3766763bf77d00b0d0c10f59c34e256acCreated 7 years agoUpdated 20 days ago
Descriptionplain2019-12-03 15:44:22
There is currently no way to get the class of an object without poking in tcl oo internals. This should be possible with a simple function p.e.:

Tcl_Obj *
Tcl_GetClassName(
    Tcl_Interp * interp,
    Tcl_Object object)
{
    Tcl_Object classPtr;
    classPtr = (Tcl_Object)(((Object *)object)->selfCls->thisPtr);
    if (classPtr == NULL) return NULL;

    return Tcl_GetObjectName(interp, classPtr);
}
dkfmarkdown2024-05-23 14:01:31

I'd go for Tcl_ObjectGetClass() or some name like that.

Tcl_Class
Tcl_ObjectGetClass(
    Tcl_Object object)
{
    return (Tcl_Class) (((Object *) object)->selfCls);
}

The retrieval of the object from the class and the name from that object would be done with existing API calls. Or we can add in those helpers; it will be helpful if we can work out which ones so we can do this in one go.

dkf Ticket [3ff0e9c376]: 3 changes [History diff]2024-08-08 10:42:15
serhiy.storchakawiki2026-11-13 11:18:44

Implemented in Tcl 9.0 by TIP 605: Tcl_GetClassOfObject returns the class of an object and Tcl_GetObjectClassName returns the name of that class.

Log in (anonymous is fine) to add a comment.