Tcl_SetAssocData(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 when interp is deleted.
  • Tcl_InterpDeleteProc **delProcPtr (in) β€” pointer to a location where the address of the current deletion procedure for the association gets stored. ignored if NULL. 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