1Tcl_SetAssocData(3) Tcl Library Procedures Tcl_SetAssocData(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_GetAssocData, Tcl_SetAssocData, Tcl_DeleteAssocData - manage asso‐
9 ciations of string keys and user specified data with Tcl interpreters.
10
12 #include <tcl.h>
13
14 ClientData
15 Tcl_GetAssocData(interp, key, delProcPtr)
16
17 Tcl_SetAssocData(interp, key, delProc, clientData)
18
19 Tcl_DeleteAssocData(interp, key)
20
22 Tcl_Interp *interp (in) Interpreter in which to
23 execute the specified
24 command. │
25
26 CONST char *key (in) │
27 Key for association with
28 which to store data or
29 from which to delete or
30 retrieve data. Typi‐
31 cally the module prefix
32 for a package.
33
34 Tcl_InterpDeleteProc *delProc (in) Procedure to call when
35 interp is deleted.
36
37 Tcl_InterpDeleteProc **delProcPtr (in) Pointer to location in
38 which to store address
39 of current deletion pro‐
40 cedure for association.
41 Ignored if NULL.
42
43 ClientData clientData (in) Arbitrary one-word value
44 associated with the
45 given key in this inter‐
46 preter. This data is
47 owned by the caller.
48_________________________________________________________________
49
50
52 These procedures allow extensions to associate their own data with a
53 Tcl interpreter. An association consists of a string key, typically
54 the name of the extension, and a one-word value, which is typically a
55 pointer to a data structure holding data specific to the extension.
56 Tcl makes no interpretation of either the key or the value for an asso‐
57 ciation.
58
59 Storage management is facilitated by storing with each association a
60 procedure to call when the interpreter is deleted. This procedure can
61 dispose of the storage occupied by the client's data in any way it sees
62 fit.
63
64 Tcl_SetAssocData creates an association between a string key and a user
65 specified datum in the given interpreter. If there is already an asso‐
66 ciation with the given key, Tcl_SetAssocData overwrites it with the new
67 information. It is up to callers to organize their use of names to
68 avoid conflicts, for example, by using package names as the keys. If
69 the deleteProc argument is non-NULL it specifies the address of a pro‐
70 cedure to invoke if the interpreter is deleted before the association
71 is deleted. DeleteProc should have arguments and result that match the
72 type Tcl_InterpDeleteProc:
73 typedef void Tcl_InterpDeleteProc(
74 ClientData clientData,
75 Tcl_Interp *interp);
76 When deleteProc is invoked the clientData and interp arguments will be
77 the same as the corresponding arguments passed to Tcl_SetAssocData.
78 The deletion procedure will not be invoked if the association is
79 deleted before the interpreter is deleted.
80
81 Tcl_GetAssocData returns the datum stored in the association with the
82 specified key in the given interpreter, and if the delProcPtr field is
83 non-NULL, the address indicated by it gets the address of the delete
84 procedure stored with this association. If no association with the
85 specified key exists in the given interpreter Tcl_GetAssocData returns
86 NULL.
87
88 Tcl_DeleteAssocData deletes an association with a specified key in the
89 given interpreter. Then it calls the deletion procedure.
90
92 association, data, deletion procedure, interpreter, key
93
94
95
96Tcl 7.5 Tcl_SetAssocData(3)