O'Reilly logo

Tcl/Tk in a Nutshell by Paul Raines, Jeff Tranter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Group Listing of Functions

Note that a few of these routines are implemented as macros for the sake of efficiency, but logically they behave the same as functions.

Tcl Objects

Tcl_Obj *Tcl_NewObj()
Tcl_Obj *Tcl_DuplicateObj(Tcl_Obj *objPtr)
void Tcl_IncrRefCount(Tcl_Obj *objPtr)
void Tcl_DecrRefCount(Tcl_Obj *objPtr)
int Tcl_IsShared(Tcl_Obj *objPtr)
void Tcl_InvalidateStringRep(Tcl_Obj *objPtr)
Tcl_Obj *Tcl_NewBooleanObj(int boolValue)
void Tcl_SetBooleanObj(Tcl_Obj *objPtr, int boolValue)
int Tcl_GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *boolPtr)
Tcl_Obj *Tcl_NewDoubleObj(double doubleValue)
void Tcl_SetDoubleObj(Tcl_Obj *objPtr, double doubleValue)
int Tcl_GetDoubleFr omObj(Tcl_Interp *interp, Tcl_Obj *objPtr, double *doublePtr)
Tcl_Obj *Tcl_NewIntObj(int intValue)
Tcl_Obj *Tcl_NewLongObj(long longValue)
void Tcl_SetIntObj(Tcl_Obj *objPtr, int intValue)
void Tcl_SetLongObj(Tcl_Obj *objPtr, long longValue)
int Tcl_GetIntFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *intPtr)
int Tcl_GetLongFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, long *longPtr)
int Tcl_ListObjAppendList(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Obj *elemListPtr)
int Tcl_ListObjAppendElement(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Obj *objPtr)
Tcl_Obj *Tcl_NewListObj(int objc, Tcl_Obj *cont objv[])
void Tcl_SetListObj(Tcl_Obj *objPtr, int objc, Tcl_Obj *const objv[])
int Tcl_ListObjGetElements(Tcl_Interp *interp, Tcl_Obj *listPtr, int *objcPtr,
    Tcl_Obj ***objvPtr)
int Tcl_ListObjIndex(Tcl_Interp *interp, Tcl_Obj *listPtr, int index,
    Tcl_Obj **objPtrPtr)
int Tcl_ListObjLength(Tcl_Interp *interp, Tcl_Obj *listPtr, int *intPtr)
int Tcl_ListObjReplace(Tcl_Interp *interp, Tcl_Obj *listPtr, int first, int count,
    int objc, Tcl_Obj *const objv[])
void Tcl_RegisterObjType(Tcl_ObjType *typePtr)
Tcl_ObjType *Tcl_GetObjType(char *typeName)
int Tcl_AppendAllObjTypes(Tcl_Interp *interp, Tcl_Obj *objPtr)
int Tcl_ConvertToT ype(Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_ObjType *typePtr)
Tcl_Obj *Tcl_NewStringObj(char *bytes, int length)
void Tcl_SetStringObj(Tcl_Obj *objPtr, char *bytes, int length)
char *Tcl_GetStringFromObj(Tcl_Obj *objPtr, int *lengthPtr)
void Tcl_AppendToObj(Tcl_Obj *objPtr, char *bytes, int length)
void Tcl_AppendStringsToObj(Tcl_Obj *interp, ...)
void Tcl_SetObjLength(Tcl_Obj *objPtr, int length)
Tcl_Obj *Tcl_ConcatObj(int objc, Tcl_Obj *const objv[])

Interpreters and Script Evaluation

Tcl_Interp *Tcl_CreateInterp(void)
void Tcl_DeleteInterp(Tcl_Interp *interp)
int Tcl_InterpDeleted(Tcl_Interp *interp)
int Tcl_Eval(Tcl_Interp *interp, char *string)
int Tcl_EvalObj(Tcl_Interp *interp, Tcl_Obj *objPtr)
int Tcl_EvalFile(Tcl_Interp *interp, char *fileName)
int Tcl_GlobalEval(Tcl_Interp *interp, char *command)
int Tcl_GlobalEvalObj(Tcl_Interp *interp, Tcl_Obj *objPtr)
int Tcl_VarEval(Tcl_Interp *interp, ...)
int Tcl_RecordAndEval(Tcl_Interp *interp, char *cmd, int flags)
int Tcl_RecordAndEvalObj(Tcl_Interp *interp, Tcl_Obj *cmdPtr, int flags)
void Tcl_AllowExceptions(Tcl_Interp *interp)
Tcl_AsyncHandler Tcl_AsyncCreate(Tcl_AsyncProc *proc, ClientData clientData)
void Tcl_AsyncMark(Tcl_AsyncHandler async)
int Tcl_AsyncInvoke(Tcl_Interp *interp, int code)
void Tcl_AsyncDelete(Tcl_AsyncHandler async)
int Tcl_AsyncReady(void)
void Tcl_CallWhenDeleted(Tcl_Interp *interp, Tcl_InterpDeleteProc *proc,
     ClientData clientData)
void Tcl_DontCallWhenDeleted(Tcl_Interp *interp, Tcl_InterpDeleteProc *proc,
     ClientData clientData)
int Tcl_IsSafe(Tcl_Interp *interp)
int Tcl_MakeSafe(Tcl_Interp *interp)
Tcl_Interp *Tcl_CreateSlave(Tcl_Interp *interp, char *slaveName, int isSafe)
Tcl_Interp *Tcl_GetSlave(Tcl_Interp *interp, char *slaveName)
Tcl_Interp *Tcl_GetMaster(Tcl_Interp *interp)
int Tcl_GetInterpPath(Tcl_Interp *askInterp, Tcl_Interp *slaveInterp)
int Tcl_CreateAlias(Tcl_Interp *slave, char *slaveCmd, Tcl_Interp *target,
    char *targetCmd, int argc, char **argv)
int Tcl_CreateAliasObj(Tcl_Interp *slave, char *slaveCmd, Tcl_Interp *target,
    char *targetCmd, int objc, Tcl_Obj *const objv[])
int Tcl_GetAlias(Tcl_Interp *interp, char *slaveCmd, Tcl_Interp **targetInterpPtr,
    char **targetCmdPtr, int *argcPtr, char ***argvPtr)
int Tcl_GetAliasObj(Tcl_Interp *interp, char *slaveCmd, Tcl_Interp **targetInterpPtr,
    char **targetCmdPtr, int *objcPtr, Tcl_Obj ***objv)
int Tcl_ExposeCommand(Tcl_Interp *interp, char *hiddenCmdToken,
    char *cmdName)
int Tcl_HideCommand(Tcl_Interp *interp, char *cmdName,
    char *hiddenCmdToken)
int Tcl_DoOneEvent(int flags)
void Tcl_DoWhenIdle(Tcl_IdleProc *proc, ClientData clientData)
void Tcl_CancelIdleCall(Tcl_IdleProc *idleProc, ClientData clientData)
void Tcl_Exit(int status)
void Tcl_Finalize(void)
void Tcl_CreateExitHandler(Tcl_ExitProc *proc, ClientData clientData)
void Tcl_DeleteExitHandler(Tcl_ExitProc *proc, ClientData clientData)
int Tcl_SetRecursionLimit(Tcl_Interp *interp, int depth)
void Tcl_StaticPackage(Tcl_Interp *interp, char *pkgName,
     Tcl_PackageInitProc *initProc, Tcl_PackageInitProc *safeInitProc)

Creating New Tcl Commands

Tcl_Command Tcl_CreateCommand(Tcl_Interp *interp, char *cmdName,
    Tcl_CmdPrc *proc, ClientData clientData, Tcl_CmdDeleteProc *deleteProc)
Tcl_Command Tcl_CreateObjCommand(Tcl_Interp *interp, char *cmdName,
    Tcl_ObjCmdProc *proc, ClientData clientData,
    Tcl_CmdDeleteProc *deleteProc)
int Tcl_DeleteCommand(Tcl_Interp *interp, char *cmdName)
int Tcl_DeleteCommandFromToken(Tcl_Interp *interp, Tcl_Command command)
void Tcl_SetResult(Tcl_Interp *interp, char *string, Tcl_Fr eeProc *freeProc)
void Tcl_AppendResult(Tcl_Interp *interp, ...)
void Tcl_AppendElement(Tcl_Interp *interp, char *string)
void Tcl_ResetResult(Tcl_Interp *interp)
int Tcl_GetCommandInfo(Tcl_Interp *interp, char *cmdName,
    Tcl_CmdInfo *infoPtr)
int Tcl_SetCommandInfo(Tcl_Interp *interp, char *cmdName, Tcl_CmdInfo *infoPtr)
char *Tcl_GetCommandName(Tcl_Interp *interp, Tcl_Command command)
void Tcl_SetObjResult(Tcl_Interp *interp, Tcl_Obj *resultObjPtr)
Tcl_Obj *Tcl_GetObjResult(Tcl_Interp *interp)
void Tcl_FreeResult(Tcl_Interp *interp)
char *Tcl_GetStringResult(Tcl_Interp *interp)

Initialization and Packages

int Tcl_AppInit(Tcl_Interp *interp)
int Tcl_Init(Tcl_Interp *interp)

Parsing

int Tcl_GetInt(Tcl_Interp *interp, char *string, int *intPtr)
int Tcl_GetDouble(Tcl_Interp *interp, char *string, double *doublePtr)
int Tcl_GetBoolean(Tcl_Interp *interp, char *string, int *boolPtr)
int Tcl_ExprString(Tcl_Interp *interp, char *string)
int Tcl_ExprLong(Tcl_Interp *interp, char *string, long *ptr)
int Tcl_ExprDouble(Tcl_Interp *interp, char *string, double *ptr)
int Tcl_ExprBoolean(Tcl_Interp *interp, char *string, int *ptr)
int Tcl_SplitList(Tcl_Interp *interp, char *list, int *argcPtr, char ***argvPtr)
char *Tcl_Merge(int argc, char **argv)
char Tcl_Backslash(const char *src, int *readPtr)
void Tcl_CreateMathFunc(Tcl_Interp *interp, char *name, int numArgs,
     Tcl_ValueType *argTypes, Tcl_MathProc *proc,
     ClientData clientData)
int Tcl_ExprLongObj(Tcl_Interp *interp, Tcl_Obj *objPtr, long *ptr)
int Tcl_ExprDoubleObj(Tcl_Interp *interp, Tcl_Obj *objPtr, double *ptr)
int Tcl_ExprBooleanObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *ptr)
int Tcl_ExprObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_Obj **resultPtrPtr)
int Tcl_GetIndexFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, char **tablePtr,
    char *msg, int flags, int *indexPtr)
void Tcl_PrintDouble(Tcl_Interp *interp, double value, char *dst)
int Tcl_ScanCountedElement(const char *string, int length, int *flagPtr)
int Tcl_ScanElement(const char *string, int *flagPtr)
int Tcl_ConvertCountedElement(const char *src, int length, char *dst, int flags)
int Tcl_ConvertElement(const char *src, char *dst, int flags)

Exceptions

void Tcl_AddErrorInfo (Tcl_Interp *interp, char *message)
void Tcl_AddObjErrorInfo(Tcl_Interp *interp, char *message, int length)
void Tcl_SetErrorCode(Tcl_Interp *arg1, ...)
void Tcl_SetObjErrorCode(Tcl_Interp *interp, Tcl_Obj *errorObjPtr)
void Tcl_BackgroundError(Tcl_Interp *interp)
void Tcl_WrongNumArgs(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[],
     char *message)

Accessing Tcl Variables

char *Tcl_SetVar(Tcl_Interp *interp, char *varName, char *newValue, int flags)
char *Tcl_SetVar2(Tcl_Interp *interp, char *part1, char *part2, char *newValue,
     int flags)
char *Tcl_GetVar(Tcl_Interp *interp, char *varName, int flags)
char *Tcl_GetVar2(Tcl_Interp *interp, char *part1, char *part2, int flags)
int Tcl_UnsetVar(Tcl_Interp *interp, char *varName, int flags)
int Tcl_UnsetVar2(Tcl_Interp *interp, char *part1, char *part2, int flags)
int Tcl_LinkVar(Tcl_Interp *interp, char *varName, char *addr, int type)
void Tcl_UnlinkVar(Tcl_Interp *interp, char *varName)
void Tcl_UpdateLinkedVar(Tcl_Interp *interp, char *varName)
int Tcl_TraceVar(Tcl_Interp *interp, char *varName, int flags,
    Tcl_VarTraceProc *proc, ClientData clientData)
int Tcl_TraceVar2(Tcl_Interp *interp, char *part1, char *part2, int flags,
    Tcl_VarTraceProc *proc, ClientData clientData)
void Tcl_UntraceVar(Tcl_Interp *interp, char *varName, int flags,
    Tcl_VarTraceProc *proc, ClientData clientData)
void Tcl_UntraceVar2(Tcl_Interp *interp, char *part1, char *part2, int flags,
    Tcl_VarTraceProc *proc, ClientData clientData)
ClientData Tcl_VarTraceInfo(Tcl_Interp *interp, char *varName, int flags,
    Tcl_VarTraceProc *procPtr, ClientData prevClientData)
ClientData Tcl_VarTraceInfo2(Tcl_Interp *interp, char *part1, char *part2, int flags,
    Tcl_VarTraceProc *procPtr, ClientData prevClientData)
Tcl_Obj *Tcl_ObjGetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
    int flags)
Tcl_Obj *Tcl_ObjSetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
    Tcl_Obj *newValuePtr, int flags)
int Tcl_UpVar(Tcl_Interp *interp, char *frameName, char *varName,
    char *localName, int flags)
int Tcl_UpVar2(Tcl_Interp *interp, char *frameName, char *part1, char *part2,
    char *localName, int flags)

Hash Tables

void Tcl_InitHashTable(Tcl_HashTable *tablePtr, int keyType)
void Tcl_DeleteHashTable(Tcl_HashTable *tablePtr)
Tcl_HashEntry *Tcl_CreateHashEntry(Tcl_hashTable *tablePtr, char *key,
    int *newPtr)
Tcl_HashEntry *Tcl_FindHashEntry(Tcl_HashTable *tablePtr, char *key)
void Tcl_DeleteHashEntry(Tcl_HashEntry *entryPtr)
ClientData Tcl_GetHashValue(Tcl_HashEntry *entryPtr)
void Tcl_SetHashValue(Tcl_HashEntry *entryPtr, Clientdata value)
char *Tcl_GetHashKey(Tcl_HashEntry *entryPtr)
Tcl_HashEntry *Tcl_FirstHashEntry(Tcl_HashTable *tablePtr,
    Tcl_HashSearch *searchPtr)
Tcl_HashEntry *Tcl_NextHashEntry(Tcl_HashSearch *searchPtr)
char *Tcl_HashStats(Tcl_HashTable *tablePtr)
ClientData Tcl_GetAssocData(Tcl_Interp *interp, char *name,
    Tcl_InterpDeleteProc **procPtr)
void Tcl_SetAssocData(Tcl_Interp *interp, char *name, Tcl_InterpDeleteProc *proc,
    ClientData clientData)
void Tcl_DeleteAssocData(Tcl_Interp *interp, char *name)

String Utilities

void Tcl_DStringInit(Tcl_DString *dsPtr)
char *Tcl_DStringAppend(Tcl_DString *dsPtr, const char *string, int length)
char *Tcl_DStringAppendElement(Tcl_DString *dsPtr, const char *string)
void Tcl_DStringStartSublist(Tcl_DString *dsPtr)
void Tcl_DStringEndSublist(Tcl_DString *dsPtr)
int Tcl_DStringLength(Tcl_DString *dsPtr)
char *Tcl_DStringValue(Tcl_DString *dsPtr)
void Tcl_DStringSetLength(Tcl_DString *dsPtr, int length)
void Tcl_DStringFree(Tcl_DString *dsPtr)
void Tcl_DStringResult(Tcl_Interp *interp, Tcl_DString *dsPtr)
void Tcl_DStringGetResult(Tcl_Interp *interp, Tcl_DString *dsPtr)
int Tcl_CommandComplete(char *cmd)
int Tcl_StringMatch(char *string, char *pattern)
int Tcl_RegExpMatch(Tcl_Interp *interp, char *string, char *pattern)
Tcl_RegExp Tcl_RegExpCompile(Tcl_Interp *interp, char *string)
int Tcl_RegExpExec(Tcl_Interp *interp, Tcl_RegExp regexp, char *string, char *start)
void Tcl_RegExpRange(Tcl_RegExp regexp, int index, char **startPtr, char **endPtr)
char *Tcl_Concat(int argc, char **argv)

POSIX Utilities

char *Tcl_TildeSubst(Tcl_Interp *interp, char *name, Tcl_DString *resultPtr)
char *Tcl_PosixError(Tcl_Interp *interp)
char *Tcl_ErrnoId(void)
char *Tcl_SignalId(int sig)
char *Tcl_SignalMsg(int sig)
void Tcl_DetachPids(int numPids, Tcl_Pid *pidPtr)
void Tcl_ReapDetachedProcs(void)
void Tcl_SetErrno(int err)
int Tcl_GetErrno(void)

Input/Output

Tcl_Channel Tcl_OpenCommandChannel(Tcl_Interp *interp, int argc, char **argv,
    int flags)
Tcl_Channel Tcl_CreateChannel(Tcl_ChannelT ype *typePtr, char *chanName,
    ClientData instanceData, int mask)
ClientData Tcl_GetChannelInstanceData(Tcl_Channel chan)
Tcl_ChannelType *Tcl_GetChannelType(Tcl_Channel chan)
char *Tcl_GetChannelName(Tcl_Channel chan)
int Tcl_GetChannelHandle(Tcl_Channel chan, int direction, ClientData *handlePtr)
int Tcl_GetChannelFlags(Tcl_Channel channel)
void Tcl_SetDefaultTranslation(TclChannel channel, Tcl_EolTranslation transMode)
int Tcl_GetChannelBufferSize(Tcl_Channel chan)
void Tcl_SetChannelBufferSize(Tcl_Channel chan, int sz)
void Tcl_NotifyChannel(Tcl_Channel channel, int mask)
int Tcl_BadChannelOption(Tcl_Interp *interp, char *optionName, char *optionList)
void Tcl_CreateChannelHandler(Tcl_Channel chan, int mask,
     Tcl_ChannelProc *proc, ClientData clientData)
void Tcl_DeleteChannelHandler(Tcl_Channel chan, Tcl_ChannelProc *proc,
     ClientData clientData)
void Tcl_CreateCloseHandler(Tcl_Channel chan, Tcl_CloseProc *proc,
     ClientData clientData)
void Tcl_DeleteCloseHandler(Tcl_Channel chan, Tcl_CloseProc *proc,
     ClientData clientData)
int Tcl_GetOpenFile(Tcl_Interp *interp, char *string, int write, int checkUsage,
    ClientData *filePtr)
Tcl_Channel Tcl_GetStdChannel(int type)
void Tcl_SetStdChannel(Tcl_Channel channel, int type)
Tcl_Channel Tcl_OpenFileChannel(Tcl_Interp *interp, char *fileName,
     char *modeString, int permissions)
Tcl_Channel Tcl_MakeFileChannel(ClientData handle, int mode)
Tcl_Channel Tcl_GetChannel(Tcl_Interp *interp, char *chanName, int *modePtr)
void Tcl_RegisterChannel(Tcl_Interp *interp, Tcl_Channel chan)
int Tcl_UnregisterChannel(Tcl_Interp *interp, Tcl_Channel chan)
int Tcl_Close(Tcl_Interp *interp, Tcl_Channel chan)
int Tcl_Read(Tcl_Channel chan, char *bufPtr, int toRead)
int Tcl_Gets(Tcl_Channel chan, Tcl_DString *dsPtr)
int Tcl_GetsObj(Tcl_Channel chan, Tcl_Obj *objPtr)
int Tcl_Write(Tcl_Channel chan, char *s, int slen)
int Tcl_Flush(Tcl_Channel chan)
int Tcl_Seek(Tcl_Channel chan, int offset, int mode)
int Tcl_Tell(Tcl_Channel chan)
int Tcl_GetChannelOption(Tcl_Interp *interp, Tcl_Channel chan,
    char *optionName, Tcl_DString *dsPtr)
int Tcl_SetChannelOption(Tcl_Interp *interp, Tcl_Channel chan, char *optionName,
    char *newValue)
int Tcl_Eof(Tcl_Channel chan)
int Tcl_InputBlocked(Tcl_Channel chan)
int Tcl_InputBuffered(Tcl_Channel chan)
Tcl_Channel Tcl_OpenTcpClient(Tcl_Interp *interp, int port, char *address,
    char *myaddr, int myport, int async)
Tcl_Channel Tcl_MakeTcpClientChannel(ClientData tcpSocket)
Tcl_Channel Tcl_OpenTcpServer(Tcl_Interp *interp, int port, char *host,
    Tcl_TcpAcceptProc *acceptProc, ClientData callbackData)
int Tcl_Ungets(Tcl_Channel chan, char *str, int len, int atHead)
int Tcl_GetChannelMode(Tcl_Channel chan)

Notifier and Events

void Tcl_CreateEventSource(Tcl_EventSetupProc *setupProc,
     Tcl_EventCheckProc *checkProc, ClientData clientData)
void Tcl_DeleteEventSource(Tcl_EventSetupProc *setupProc,
     Tcl_EventCheckProc *checkProc, ClientData clientData)
void Tcl_SetMaxBlockTime(Tcl_Time *timePtr)
void Tcl_QueueEvent(Tcl_Event *evPtr, Tcl_QueuePosition position)
void Tcl_DeleteEvents(Tcl_EventDeleteProc *proc, ClientData clientData)
int Tcl_WaitForEvent(Tcl_Time *timePtr)
void Tcl_SetTimer(Tcl_Time *timePtr)
int Tcl_ServiceAll(void)
int Tcl_ServiceEvent(int flags)
int Tcl_GetServiceMode(void)
int Tcl_SetServiceMode(int mode)

Miscellaneous

char *Tcl_Alloc(int size)
void Tcl_Free(char *ptr)
char *Tcl_Realloc(char *ptr, int size)
void Tcl_CreateFileHandler(int fd, int mask, Tcl_FileProc *proc,
     ClientData clientData)
void Tcl_DeleteFileHandler(int fd)
Tcl_TimerToken Tcl_CreateTimerHandler(int milliseconds, Tcl_TimerProc *proc,
     ClientData clientData)
void Tcl_DeleteTimerHandler(Tcl_TimerToken token)
Tcl_Trace Tcl_CreateTrace(Tcl_Interp *interp, int level, Tcl_CmdTraceProc *proc,
    ClientData clientData)
void Tcl_DeleteTrace(Tcl_Interp *interp, Tcl_Trace trace)
void Tcl_FindExecutable(char *argv0)
int Tcl_PkgProvide(Tcl_Interp *interp, char *name, char *version)
char *Tcl_PkgRequire(Tcl_Interp *interp, char *name, char *version, int exact)
void Tcl_Preserve(ClientData data)
void Tcl_Release(ClientData clientData)
void Tcl_EventuallyFree(ClientData clientData, Tcl_FreeProc *freeProc)
void Tcl_Sleep(int ms)
void Tcl_SplitPath(char *path, int *argcPtr, char ***argvPtr)
char *Tcl_JoinPath(int argc, char **argv, Tcl_DString *resultPtr)
Tcl_PathT ype Tcl_GetPathType(char *path)
void Tcl_Main(int argc, char **argv, Tcl_AppInitProc *appInitProc
char *Tcl_TranslateFileName(Tcl_Interp *interp, char *name, Tcl_DString *bufferPtr)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required