Tcl_SetAssocData(3tcl)
β¨ Tcl_SetAssocData β bestie, let's talk about interpreter side-quests β¨
okay so this is a page from the Tcl Library Procedures manual, and it's literally all about Tcl_GetAssocData, Tcl_SetAssocData, and Tcl_DeleteAssocData β the three little functions that let you manage associations of string keys and user specified data with Tcl interpreters. iykyk π
πΈ NAME πΈ
Tcl_GetAssocData, Tcl_SetAssocData, Tcl_DeleteAssocData β manage associations of string keys and user specified data with Tcl interpreters. no cap, that's the whole job π«Ά
π SYNOPSIS π
#include <tcl.h>
void *
Tcl_GetAssocData(interp, key, delProcPtr)
Tcl_SetAssocData(interp, key, delProc, clientData)
Tcl_DeleteAssocData(interp, key)
π ARGUMENTS π
Tcl_Interp *interp(in) β the interpreter where you wanna execute the specified command. it's the main character of this whole page πconst char *key(in) β the key for the association, i.e. the thing you store data under, delete data from, or retrieve data by. typically the module prefix for a package πTcl_InterpDeleteProc *delProc(in) β the procedure to call wheninterpis deleted.Tcl_InterpDeleteProc **delProcPtr(in) β pointer to a location where the address of the current deletion procedure for the association gets stored. ignored ifNULL. yes bestie, ignored, she's off duty πvoid *clientData(in) β arbitrary one-word value associated with the given key in this interpreter. this data is owned by the caller, so don't come for Tcl when you gotta free it π
β¨ DESCRIPTION β¨
so basically these procedures let extensions associate their own data with a Tcl interpreter. an association is two things: a string key (typically the name of the extension) and a one-word value (typically a pointer to a data structure holding data specific to the extension). and here's the vibe β Tcl makes no interpretation of either the key or the value for an association. she does not read your diary. she does not judge your struct. she just holds it π«Ά
storage management gets a glow-up because each association also stores a procedure to call when the interpreter is deleted. that procedure can dispose of the storage occupied by the client's data in any way it sees fit. freedom, periodt π
π Tcl_SetAssocData
Tcl_SetAssocData creates an association between a string key and a user specified datum in the given interpreter. if there's already an association with the given key, Tcl_SetAssocData overwrites it with the new information β no warning, no drama, it just replaces it π. it is up to callers to organize their use of names to avoid conflicts, for example, by using package names as the keys. so like, pick your key names carefully bestie, don't be out here colliding π
if the deleteProc argument is non-NULL it specifies the address of a procedure to invoke if the interpreter is deleted before the association is deleted. DeleteProc should have arguments and result that match the type Tcl_InterpDeleteProc:
typedef void Tcl_InterpDeleteProc(
void *clientData,
Tcl_Interp *interp);
when deleteProc is invoked, the clientData and interp arguments will be the same as the corresponding arguments passed to Tcl_SetAssocData. and heads up β the deletion procedure will not be invoked if the association is deleted before the interpreter is deleted. it's giving "you only get one farewell" π¦
π Tcl_GetAssocData
Tcl_GetAssocData returns the datum stored in the association with the specified key in the given interpreter, and if the delProcPtr field is non-NULL, the address indicated by it gets the address of the delete procedure stored with this association. and if no association with the specified key exists in the given interpreter, Tcl_GetAssocData returns NULL. she said "not found, moving on" π
π§ Tcl_DeleteAssocData
Tcl_DeleteAssocData deletes an association with a specified key in the given interpreter. then it calls the deletion procedure. so it's not just gone, it's gone with a proper goodbye β¨
π KEYWORDS π
association, data, deletion procedure, interpreter, key
and that's the whole page, bestie β go forth and associate responsibly π«Ά this was served up from the Tcl Library Procedures manual, Tcl 7.5 era, under the title Tcl_SetAssocData(3tcl). slay πβ¨π
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1995-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms