Debian Codegraph @

embedded/www/files/critcl_iassoc.html

raw
1 <!DOCTYPE html><html><head>
2 <meta charset="UTF-8">
3 <meta name="viewport" content="width=device-width, initial-scale=1">
4 <title>critcl::iassoc - C Runtime In Tcl (CriTcl)</title>
5 <style type="text/css"><!--
6 HTML {
7 background: #FFFFFF;
8 color: black;
9 }
10 BODY {
11 background: #FFFFFF;
12 color: black;
13 }
14 DIV.doctools {
15 margin-left: 10%;
16 margin-right: 10%;
17 }
18 DIV.doctools H1,DIV.doctools H2 {
19 margin-left: -5%;
20 }
21 H1, H2, H3, H4 {
22 margin-top: 1em;
23 font-family: sans-serif;
24 font-size: large;
25 color: #005A9C;
26 background: transparent;
27 text-align: left;
28 }
29 H1.doctools_title {
30 text-align: center;
31 }
32 UL,OL {
33 margin-right: 0em;
34 margin-top: 3pt;
35 margin-bottom: 3pt;
36 }
37 UL LI {
38 list-style: disc;
39 }
40 OL LI {
41 list-style: decimal;
42 }
43 DT {
44 padding-top: 1ex;
45 }
46 UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
47 font: normal 12pt/14pt sans-serif;
48 list-style: none;
49 }
50 LI.doctools_section, LI.doctools_subsection {
51 list-style: none;
52 margin-left: 0em;
53 text-indent: 0em;
54 padding: 0em;
55 }
56 PRE {
57 display: block;
58 font-family: monospace;
59 white-space: pre;
60 margin: 0%;
61 padding-top: 0.5ex;
62 padding-bottom: 0.5ex;
63 padding-left: 1ex;
64 padding-right: 1ex;
65 width: 100%;
66 }
67 PRE.doctools_example {
68 color: black;
69 background: #f5dcb3;
70 border: 1px solid black;
71 }
72 UL.doctools_requirements LI, UL.doctools_syntax LI {
73 list-style: none;
74 margin-left: 0em;
75 text-indent: 0em;
76 padding: 0em;
77 }
78 DIV.doctools_synopsis {
79 color: black;
80 background: #80ffff;
81 border: 1px solid black;
82 font-family: serif;
83 margin-top: 1em;
84 margin-bottom: 1em;
85 }
86 UL.doctools_syntax {
87 margin-top: 1em;
88 border-top: 1px solid black;
89 }
90 UL.doctools_requirements {
91 margin-bottom: 1em;
92 border-bottom: 1px solid black;
93 }
94 --></style>
95 </head>
96 <!-- Generated from file 'critcl_iassoc.man' by tcllib/doctools with format 'html'
97 -->
98 <!-- Copyright &amp;copy; 2011-2024 Andreas Kupries
99 -->
100 <!-- critcl::iassoc.n
101 -->
102 <body><hr> [
103 <a href="../toc.html">Table Of Contents</a>
104 &#124; <a href="../index.html">Keyword Index</a>
105 ] <hr>
106 <div class="doctools">
107 <h1 class="doctools_title">critcl::iassoc(n) 1.2 doc &quot;C Runtime In Tcl (CriTcl)&quot;</h1>
108 <div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
109 <p>critcl::iassoc - CriTcl - Code Gen - Tcl Interp Associations</p>
110 </div>
111 <div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
112 <ul class="doctools_toc">
113 <li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
114 <li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
115 <li class="doctools_section"><a href="#section1">Description</a></li>
116 <li class="doctools_section"><a href="#section2">API</a></li>
117 <li class="doctools_section"><a href="#section3">Example</a></li>
118 <li class="doctools_section"><a href="#section4">Authors</a></li>
119 <li class="doctools_section"><a href="#section5">Bugs, Ideas, Feedback</a></li>
120 <li class="doctools_section"><a href="#keywords">Keywords</a></li>
121 <li class="doctools_section"><a href="#category">Category</a></li>
122 <li class="doctools_section"><a href="#copyright">Copyright</a></li>
123 </ul>
124 </div>
125 <div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
126 <div class="doctools_synopsis">
127 <ul class="doctools_requirements">
128 <li>package require <b class="pkgname">Tcl 8.6</b></li>
129 <li>package require <b class="pkgname">critcl <span class="opt">?3.2?</span></b></li>
130 <li>package require <b class="pkgname">critcl::iassoc <span class="opt">?1.2?</span></b></li>
131 </ul>
132 <ul class="doctools_syntax">
133 <li><a href="#1"><b class="cmd">::critcl::iassoc::def</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">struct</i> <i class="arg">constructor</i> <i class="arg">destructor</i></a></li>
134 </ul>
135 </div>
136 </div>
137 <div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
138 <p>Be welcome to the <i class="term">C Runtime In Tcl</i> (short: <i class="term"><a href="critcl.html">CriTcl</a></i>), a system for embedding and using C
139 code from within <a href="http://core.tcl-lang.org/tcl">Tcl</a> scripts.</p>
140 <p>This document is the reference manpage for the <b class="package">critcl::iassoc</b>
141 package. This package provides convenience commands for advanced
142 functionality built on top of the critcl core.</p>
143 <p>With it a user wishing to associate some data with a Tcl
144 interpreter via Tcl's <b class="function">Tcl_(Get|Set)AssocData()</b> APIs can now
145 concentrate on the data itself, while all the necessary boilerplate
146 around it is managed by this package.</p>
147 <p>Its intended audience are mainly developers wishing to write
148 Tcl packages with embedded C code.</p>
149 <p>This package resides in the Core Package Layer of CriTcl.</p>
150 <p><img alt="arch_core" src="../image/arch_core.png"></p>
151 </div>
152 <div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2>
153 <dl class="doctools_definitions">
154 <dt><a name="1"><b class="cmd">::critcl::iassoc::def</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">struct</i> <i class="arg">constructor</i> <i class="arg">destructor</i></a></dt>
155 <dd><p>This command defines a C function with the given <i class="arg">name</i> which
156 provides access to a structure associated with a Tcl interpreter.</p>
157 <p>The C code code fragment <i class="arg">struct</i> defines the elements of
158 said structure, whereas the fragments <i class="arg">constructor</i> and
159 <i class="arg">destructor</i> are C code blocks executed to initialize and release
160 any dynamically allocated parts of this structure, when needed. Note
161 that the structure itself is managed by the system.</p>
162 <p>The new function takes a <b class="const">Tcl_Interp*</b> pointer refering
163 to the interpreter whose structure we wish to obtain as the first
164 argument, plus the specified <i class="arg">arguments</i> and returns a pointer to
165 the associated structure, of type &quot;<i class="arg">name</i>_data&quot; (see below).</p>
166 <p>The <i class="arg">arguments</i> are a dictionary-like list of C types and
167 identifiers specifying additional arguments for the accessor function,
168 and, indirectly, the <i class="arg">constructor</i> C code block. This is useful
169 for the supplication of initialization values, or the return of more
170 complex error information in case of a construction failure.</p>
171 <p>The C types associated with the structure are derived from
172 <i class="arg">name</i>, with &quot;<i class="arg">name</i>_data__&quot; the type of the structure itself,
173 and &quot;<i class="arg">name</i>_data&quot; representing a pointer to the structure.
174 The C code blocks can rely on the following C environments:</p>
175 <dl class="doctools_definitions">
176 <dt><i class="arg">constructor</i></dt>
177 <dd><dl class="doctools_definitions">
178 <dt><b class="variable">data</b></dt>
179 <dd><p>Pointer to the structure (type: <i class="arg">name</i>_data) to
180 initialize.</p></dd>
181 <dt><b class="variable">interp</b></dt>
182 <dd><p>Pointer to the Tcl interpreter (type: Tcl_Interp*)
183 the new structure will be associated with.</p></dd>
184 <dt>error</dt>
185 <dd><p>A C code label the constructor can jump to should it have
186 to signal a construction failure. It is the responsibility of the
187 constructor to release any fields already initialized before jumping
188 to this label.</p></dd>
189 <dt>...</dt>
190 <dd><p>The names of the constructor arguments specified with
191 <i class="arg">arguments</i>.</p></dd>
192 </dl></dd>
193 <dt><i class="arg">destructor</i></dt>
194 <dd><dl class="doctools_definitions">
195 <dt><b class="variable">data</b></dt>
196 <dd><p>Pointer to the structure being released.</p></dd>
197 <dt><b class="variable">interp</b></dt>
198 <dd><p>Pointer to the Tcl interpreter the structure
199 belonged to.</p></dd>
200 </dl></dd>
201 </dl></dd>
202 </dl>
203 </div>
204 <div id="section3" class="doctools_section"><h2><a name="section3">Example</a></h2>
205 <p>The example shown below is the specification of a simple interpreter-associated
206 counter. The full example, with meta data and other incidentals, can be found
207 in the directory &quot;<b class="file">examples/queue</b>&quot; of the critcl source
208 distribution/repository.</p>
209 <pre class="doctools_example">
210 package require Tcl 8.6
211 package require critcl 3.2
212 critcl::buildrequirement {
213 package require critcl::iassoc
214 }
215 critcl::iassoc::def icounter {} {
216 int counter; /* The counter variable */
217 } {
218 data-&gt;counter = 0;
219 } {
220 /* Nothing to release */
221 }
222 critcl::ccode {
223 ... function (...)
224 {
225 /* Access to the data ... */
226 icounter_data D = icounter (interp /* ... any declared arguments, here, none */);
227 ... D-&gt;counter ...
228 }
229 }
230 # or, of course, 'cproc's, 'ccommand's etc.
231 package provide icounter 1
232 </pre>
233 </div>
234 <div id="section4" class="doctools_section"><h2><a name="section4">Authors</a></h2>
235 <p>Andreas Kupries</p>
236 </div>
237 <div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2>
238 <p>This document, and the package it describes, will undoubtedly contain
239 bugs and other problems.
240 Please report such at <a href="https://github.com/andreas-kupries/critcl">https://github.com/andreas-kupries/critcl</a>.
241 Please also report any ideas for enhancements you may have for either
242 package and/or documentation.</p>
243 </div>
244 <div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
245 <p><a href="../index.html#c_code">C code</a>, <a href="../index.html#embedded_c_code">Embedded C Code</a>, <a href="../index.html#tcl_interp_association">Tcl Interp Association</a>, <a href="../index.html#code_generator">code generator</a>, <a href="../index.html#compile_run">compile &amp; run</a>, <a href="../index.html#compiler">compiler</a>, <a href="../index.html#dynamic_code_generation">dynamic code generation</a>, <a href="../index.html#dynamic_compilation">dynamic compilation</a>, <a href="../index.html#generate_package">generate package</a>, <a href="../index.html#linker">linker</a>, <a href="../index.html#on_demand_compilation">on demand compilation</a>, <a href="../index.html#on_the_fly_compilation">on-the-fly compilation</a>, <a href="../index.html#singleton">singleton</a></p>
246 </div>
247 <div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
248 <p>Glueing/Embedded C code</p>
249 </div>
250 <div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
251 <p>Copyright &copy; 2011-2024 Andreas Kupries</p>
252 </div>
253 </div></body></html>