This is not necessarily the current version of this TIP.
| TIP: | 117 |
| Title: | Object Type Introspection |
| Version: | $Revision: 1.2 $ |
| Author: | Peter Spjuth <peter dot spjuth at space dot se> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Friday, 01 November 2002 |
This TIP proposes to add a subcommand to info to give information on the current internal representation of an object.
When trying to understand the internals of objects and when trying to track down shimmering problems it is very helpful to be able to see what type an object currently has.
This small gap in Tcl's introspection abilities can be filled with a simple addition to the info command.
A new subcommand, objtype, is added to info with the syntax:
info objtype ?value?
If no value is submitted, a list of all currently registered object types are return.
If a value is submitted, it returns a list where the first element is the name of value's object type, or "none" if there is no internal representation. The second element is a boolean of the form yes/no stating if the object has a valid string representation.
% info objtype
boolean index double end-offset wideInt list cmdName bytecode
nsName procbody bytearray int {array search} string
% set apa hejsan
hejsan
% info objtype $apa
none yes
% string length $apa
6
% info objtype $apa
string yes
% regexp $apa hoppsan
0
% info objtype $apa
regexp yes
% info objtype [expr 1+1]
int no
static int
InfoObjTypeCmd(dummy, interp, objc, objv)
ClientData dummy; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
Tcl_Obj *listPtr;
if ((objc != 2) && (objc != 3)) {
Tcl_WrongNumArgs(interp, 2, objv, "?value?");
return TCL_ERROR;
}
listPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
if (objc == 2) {
Tcl_AppendAllObjTypes(interp, listPtr);
} else {
Tcl_ListObjAppendElement(interp, listPtr, Tcl_NewStringObj(
(objv[2]->typePtr != NULL) ? objv[2]->typePtr->name : "none", -1));
Tcl_ListObjAppendElement(interp, listPtr,
Tcl_NewStringObj((objv[2]->bytes != NULL) ? "yes" : "no", -1));
}
Tcl_SetObjResult(interp, listPtr);
return TCL_OK;
}
For further object introspection the command can easily be extended by options.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.