SYNOPSIS
#include <tcl.h>
Tcl_RegisterObjType(typePtr)
Tcl_ObjType * Tcl_GetObjType(typeName)
int Tcl_AppendAllObjTypes(interp, objPtr)
int Tcl_ConvertToType(interp, objPtr, typePtr)
ARGUMENTS
- Tcl_ObjType *typePtr (in)
-
Points to the structure containing information about the Tcl object type. This storage must must live forever, typically by being statically allocated.
- char *typeName (in)
-
The name of a Tcl object type that
Tcl_GetObjType() should look up. - Tcl_Interp *interp (in)
-
Interpreter to use for error reporting.
- Tcl_Obj *objPtr (in)
-
For
Tcl_AppendAllObjTypes() , this points to the object onto which it appends the name of each object type as a list element. ForTcl_ConvertToType() , this points to an object that must have been the result of a previous call toTcl_NewObj() .
DESCRIPTION
The procedures in this reference page manage Tcl object types. The are used to register new object types, look up types, and force conversions from one type to another.
THE TCL_OBJTYPE STRUCTURE
Extension writers can define new object types by defining four
procedures,
initializing a Tcl_ObjType structure to describe the type,
and calling
typedef struct Tcl_ObjType { char *name; Tcl_FreeInternalRepProc *freeIntRepProc; Tcl_DupInternalRepProc *dupIntRepProc; Tcl_UpdateStringProc *updateStringProc; Tcl_SetFromAnyProc *setFromAnyProc; } Tcl_ObjType;
The name member describes the name of the type, for example,
int.
Extension writers can look up an object type using its name
with the
The setFromAnyProc member contains the address of a function called to create a valid internal representation from an object's string representation.
typedef int (Tcl_SetFromAnyProc) (Tcl_Interp *interp, Tcl_Obj *objPtr);
If an internal representation can't be created from the string,
it returns TCL_ERROR and puts a message
describing the error in the result object for interp
unless interp is NULL.
If setFromAnyProc is successful,
it stores the new internal representation,
sets objPtr's typePtr member to point to
setFromAnyProc's Tcl_ObjType, and returns
TCL_OK.
Before setting the new internal representation,
the setFromAnyProc must free any internal representation
of objPtr's old type;
it does this by calling the old type's freeIntRepProc
if it is not NULL.
As an example, the setFromAnyProc for the builtin Tcl integer
type
gets an up-to-date string representation for objPtr
by calling
The updateStringProc member contains the address of a function called to create a valid string representation from an object's internal representation.
typedef void (Tcl_UpdateStringProc) (Tcl_Obj *objPtr);
objPtr's bytes member is always
NULL when it is called.
It must always set bytes non-NULL before
returning.
We require the string representation's byte array
to have a null after the last byte, at offset length;
this allows string representations that do not contain null bytes
to be treated as conventional null character-terminated C strings.
Storage for the byte array must be allocated in the heap by
The dupIntRepProc member contains the address of a function called to copy an internal representation from one object to another.
typedef void (Tcl_DupInternalRepProc) (Tcl_Obj *srcPtr, Tcl_Obj *dupPtr);
dupPtr's internal representation is made a copy of srcPtr's internal representation. Before the call, srcPtr's internal representation is valid and dupPtr's is not. srcPtr's object type determines what copying its internal representation means. For example, the dupIntRepProc for the Tcl integer type simply copies an integer. The builtin list type's dupIntRepProc allocates a new array that points at the original element objects; the elements are shared between the two lists (and their reference counts are incremented to reflect the new references).
The freeIntRepProc member contains the address of a function that is called when an object is freed.
typedef void (Tcl_FreeInternalRepProc) (Tcl_Obj *objPtr);
The freeIntRepProc function can deallocate the storage for the object's internal representation and do other type-specific processing necessary when an object is freed. For example, Tcl list objects have an internalRep.otherValuePtr that points to an array of pointers to each element in the list. The list type's freeIntRepProc decrements the reference count for each element object (since the list will no longer refer to those objects), then deallocates the storage for the array of pointers. The freeIntRepProc member can be set to NULL to indicate that the internal representation does not require freeing.
PORTABILITY
Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
Tcl_DecrRefCount() ,Tcl_IncrRefCount() ,Tcl_NewObj()
PTC MKS Toolkit 10.4 Documentation Build 39.