Debian Codegraph @

embedded/man/files/critcl_class.n

raw
1 '\"
2 '\" Generated from file 'critcl_class\&.man' by tcllib/doctools with format 'nroff'
3 '\" Copyright (c) 2011-2024 Andreas Kupries
4 '\"
5 .TH "critcl::class" n 1\&.1 doc "C Runtime In Tcl (CriTcl)"
6 .\" The -*- nroff -*- definitions below are for supplemental macros used
7 .\" in Tcl/Tk manual entries.
8 .\"
9 .\" .AP type name in/out ?indent?
10 .\" Start paragraph describing an argument to a library procedure.
11 .\" type is type of argument (int, etc.), in/out is either "in", "out",
12 .\" or "in/out" to describe whether procedure reads or modifies arg,
13 .\" and indent is equivalent to second arg of .IP (shouldn't ever be
14 .\" needed; use .AS below instead)
15 .\"
16 .\" .AS ?type? ?name?
17 .\" Give maximum sizes of arguments for setting tab stops. Type and
18 .\" name are examples of largest possible arguments that will be passed
19 .\" to .AP later. If args are omitted, default tab stops are used.
20 .\"
21 .\" .BS
22 .\" Start box enclosure. From here until next .BE, everything will be
23 .\" enclosed in one large box.
24 .\"
25 .\" .BE
26 .\" End of box enclosure.
27 .\"
28 .\" .CS
29 .\" Begin code excerpt.
30 .\"
31 .\" .CE
32 .\" End code excerpt.
33 .\"
34 .\" .VS ?version? ?br?
35 .\" Begin vertical sidebar, for use in marking newly-changed parts
36 .\" of man pages. The first argument is ignored and used for recording
37 .\" the version when the .VS was added, so that the sidebars can be
38 .\" found and removed when they reach a certain age. If another argument
39 .\" is present, then a line break is forced before starting the sidebar.
40 .\"
41 .\" .VE
42 .\" End of vertical sidebar.
43 .\"
44 .\" .DS
45 .\" Begin an indented unfilled display.
46 .\"
47 .\" .DE
48 .\" End of indented unfilled display.
49 .\"
50 .\" .SO ?manpage?
51 .\" Start of list of standard options for a Tk widget. The manpage
52 .\" argument defines where to look up the standard options; if
53 .\" omitted, defaults to "options". The options follow on successive
54 .\" lines, in three columns separated by tabs.
55 .\"
56 .\" .SE
57 .\" End of list of standard options for a Tk widget.
58 .\"
59 .\" .OP cmdName dbName dbClass
60 .\" Start of description of a specific option. cmdName gives the
61 .\" option's name as specified in the class command, dbName gives
62 .\" the option's name in the option database, and dbClass gives
63 .\" the option's class in the option database.
64 .\"
65 .\" .UL arg1 arg2
66 .\" Print arg1 underlined, then print arg2 normally.
67 .\"
68 .\" .QW arg1 ?arg2?
69 .\" Print arg1 in quotes, then arg2 normally (for trailing punctuation).
70 .\"
71 .\" .PQ arg1 ?arg2?
72 .\" Print an open parenthesis, arg1 in quotes, then arg2 normally
73 .\" (for trailing punctuation) and then a closing parenthesis.
74 .\"
75 .\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
76 .if t .wh -1.3i ^B
77 .nr ^l \n(.l
78 .ad b
79 .\" # Start an argument description
80 .de AP
81 .ie !"\\$4"" .TP \\$4
82 .el \{\
83 . ie !"\\$2"" .TP \\n()Cu
84 . el .TP 15
85 .\}
86 .ta \\n()Au \\n()Bu
87 .ie !"\\$3"" \{\
88 \&\\$1 \\fI\\$2\\fP (\\$3)
89 .\".b
90 .\}
91 .el \{\
92 .br
93 .ie !"\\$2"" \{\
94 \&\\$1 \\fI\\$2\\fP
95 .\}
96 .el \{\
97 \&\\fI\\$1\\fP
98 .\}
99 .\}
100 ..
101 .\" # define tabbing values for .AP
102 .de AS
103 .nr )A 10n
104 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
105 .nr )B \\n()Au+15n
106 .\"
107 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
108 .nr )C \\n()Bu+\\w'(in/out)'u+2n
109 ..
110 .AS Tcl_Interp Tcl_CreateInterp in/out
111 .\" # BS - start boxed text
112 .\" # ^y = starting y location
113 .\" # ^b = 1
114 .de BS
115 .br
116 .mk ^y
117 .nr ^b 1u
118 .if n .nf
119 .if n .ti 0
120 .if n \l'\\n(.lu\(ul'
121 .if n .fi
122 ..
123 .\" # BE - end boxed text (draw box now)
124 .de BE
125 .nf
126 .ti 0
127 .mk ^t
128 .ie n \l'\\n(^lu\(ul'
129 .el \{\
130 .\" Draw four-sided box normally, but don't draw top of
131 .\" box if the box started on an earlier page.
132 .ie !\\n(^b-1 \{\
133 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134 .\}
135 .el \}\
136 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
137 .\}
138 .\}
139 .fi
140 .br
141 .nr ^b 0
142 ..
143 .\" # VS - start vertical sidebar
144 .\" # ^Y = starting y location
145 .\" # ^v = 1 (for troff; for nroff this doesn't matter)
146 .de VS
147 .if !"\\$2"" .br
148 .mk ^Y
149 .ie n 'mc \s12\(br\s0
150 .el .nr ^v 1u
151 ..
152 .\" # VE - end of vertical sidebar
153 .de VE
154 .ie n 'mc
155 .el \{\
156 .ev 2
157 .nf
158 .ti 0
159 .mk ^t
160 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
161 .sp -1
162 .fi
163 .ev
164 .\}
165 .nr ^v 0
166 ..
167 .\" # Special macro to handle page bottom: finish off current
168 .\" # box/sidebar if in box/sidebar mode, then invoked standard
169 .\" # page bottom macro.
170 .de ^B
171 .ev 2
172 'ti 0
173 'nf
174 .mk ^t
175 .if \\n(^b \{\
176 .\" Draw three-sided box if this is the box's first page,
177 .\" draw two sides but no top otherwise.
178 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
179 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
180 .\}
181 .if \\n(^v \{\
182 .nr ^x \\n(^tu+1v-\\n(^Yu
183 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
184 .\}
185 .bp
186 'fi
187 .ev
188 .if \\n(^b \{\
189 .mk ^y
190 .nr ^b 2
191 .\}
192 .if \\n(^v \{\
193 .mk ^Y
194 .\}
195 ..
196 .\" # DS - begin display
197 .de DS
198 .RS
199 .nf
200 .sp
201 ..
202 .\" # DE - end display
203 .de DE
204 .fi
205 .RE
206 .sp
207 ..
208 .\" # SO - start of list of standard options
209 .de SO
210 'ie '\\$1'' .ds So \\fBoptions\\fR
211 'el .ds So \\fB\\$1\\fR
212 .SH "STANDARD OPTIONS"
213 .LP
214 .nf
215 .ta 5.5c 11c
216 .ft B
217 ..
218 .\" # SE - end of list of standard options
219 .de SE
220 .fi
221 .ft R
222 .LP
223 See the \\*(So manual entry for details on the standard options.
224 ..
225 .\" # OP - start of full description for a single option
226 .de OP
227 .LP
228 .nf
229 .ta 4c
230 Command-Line Name: \\fB\\$1\\fR
231 Database Name: \\fB\\$2\\fR
232 Database Class: \\fB\\$3\\fR
233 .fi
234 .IP
235 ..
236 .\" # CS - begin code excerpt
237 .de CS
238 .RS
239 .nf
240 .ta .25i .5i .75i 1i
241 ..
242 .\" # CE - end code excerpt
243 .de CE
244 .fi
245 .RE
246 ..
247 .\" # UL - underline word
248 .de UL
249 \\$1\l'|0\(ul'\\$2
250 ..
251 .\" # QW - apply quotation marks to word
252 .de QW
253 .ie '\\*(lq'"' ``\\$1''\\$2
254 .\"" fix emacs highlighting
255 .el \\*(lq\\$1\\*(rq\\$2
256 ..
257 .\" # PQ - apply parens and quotation marks to word
258 .de PQ
259 .ie '\\*(lq'"' (``\\$1''\\$2)\\$3
260 .\"" fix emacs highlighting
261 .el (\\*(lq\\$1\\*(rq\\$2)\\$3
262 ..
263 .\" # QR - quoted range
264 .de QR
265 .ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
266 .\"" fix emacs highlighting
267 .el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
268 ..
269 .\" # MT - "empty" string
270 .de MT
271 .QW ""
272 ..
273 .BS
274 .SH NAME
275 critcl::class \- CriTcl - Code Gen - C Classes
276 .SH SYNOPSIS
277 package require \fBTcl 8\&.6\fR
278 .sp
279 package require \fBcritcl ?3\&.2?\fR
280 .sp
281 package require \fBcritcl::class ?1\&.1?\fR
282 .sp
283 \fB::critcl::class::define\fR \fIname\fR \fIscript\fR
284 .sp
285 \fBinclude\fR \fIpath\fR
286 .sp
287 \fBsupport\fR \fIcode\fR
288 .sp
289 \fBtype\fR \fIname\fR
290 .sp
291 \fBclassconstructor\fR \fIbody\fR
292 .sp
293 \fBclassdestructor\fR \fIbody\fR
294 .sp
295 \fBconstructor\fR \fIbody\fR ?\fIpostbody\fR?
296 .sp
297 \fBdestructor\fR \fIbody\fR
298 .sp
299 \fBclassvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
300 .sp
301 \fBclassmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
302 .sp
303 \fBclassmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
304 .sp
305 \fBclassmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
306 .sp
307 \fBinsvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
308 .sp
309 \fBmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
310 .sp
311 \fBmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
312 .sp
313 \fBmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
314 .sp
315 \fBmethod_introspection\fR
316 .sp
317 .BE
318 .SH DESCRIPTION
319 .PP
320 Be welcome to the \fIC Runtime In Tcl\fR (short: \fICriTcl\fR), a system for embedding and using C
321 code from within \fITcl\fR [http://core\&.tcl-lang\&.org/tcl] scripts\&.
322 .PP
323 This document is the reference manpage for the \fBcritcl::class\fR
324 package\&. This package provides convenience commands for advanced
325 functionality built on top of the core\&.
326 .PP
327 With it a user wishing to create a C level object with class
328 and instance commands can concentrate on specifying the class- and
329 instance-variables and -methods in a manner similar to a TclOO class,
330 while all the necessary boilerplate around it is managed by this
331 package\&.
332 .PP
333 Its intended audience are mainly developers wishing to write
334 Tcl packages with embedded C code\&.
335 .PP
336 This package resides in the Core Package Layer of CriTcl\&.
337 .PP
338 .PS
339 .nf
340 +----------------+
341 |Applications |
342 | critcl |
343 | critcl::app |
344 +----------------+
345
346 *================*
347 |Core Packages |
348 | critcl |
349 | critcl::util |
350 *================*
351
352 +----------------+
353 |Support Packages|
354 | stubs::* |
355 | md5, platform |
356 | \&.\&.\&. |
357 +----------------+
358
359 .fi
360 .PE
361 .PP
362 .SH API
363 .TP
364 \fB::critcl::class::define\fR \fIname\fR \fIscript\fR
365 This is the main command to define a new class \fIname\fR, where
366 \fIname\fR is the name of the Tcl command representing the class,
367 i\&.e\&. the \fIclass command\fR\&. The \fIscript\fR provides the
368 specification of the class, i\&.e\&. information about included headers,
369 class- and instance variables, class- and instance-methods, etc\&.
370 See the section \fBClass Specification API\fR below for the
371 detailed list of the available commands and their semantics\&.
372 .PP
373 .SH "CLASS SPECIFICATION API"
374 Here we documents all class specification commands available inside of
375 the class definition script argument of \fB::critcl::class::define\fR\&.
376 .SS "GENERAL CONFIGURATION"
377 .TP
378 \fBinclude\fR \fIpath\fR
379 This command specifies the path of a header file to include within the
380 code generated for the class\&. This is separate from the \fBsupport\fR
381 because the generated include directives will be put at the very
382 beginning of the generated code\&. This is done to allow the use of the
383 imported declarations within the instance type, and elsewhere\&.
384 .sp
385 Calls to this command are cumulative\&.
386 It is of course possible to not use this command at all, for classes
387 not making use of external definitions\&.
388 .sp
389 The result is the empty string\&.
390 .TP
391 \fBsupport\fR \fIcode\fR
392 This command specifies supporting C code, i\&.e\&. any definitions (types,
393 functions, etc\&.) needed by the \fIwhole\fR class and not fitting into
394 class- and instance-methods\&. The code is embedded at global level,
395 outside of any function or other definition\&.
396 .sp
397 Calls to this command are cumulative\&.
398 It is of course possible to not use this command at all, for classes
399 not requiring supporting code\&.
400 .sp
401 The result of the command is the empty string\&.
402 .TP
403 \fBtype\fR \fIname\fR
404 This command specifies the name of an external C type to be used as
405 the type of the instance structure\&.
406 .sp
407 Initialization and release of the structure with the given type
408 are the responsibility of the user, through \fBconstructor\fR and
409 \fBdestructor\fR code fragments\&.
410 .sp
411 \fIAttention:\fR Using this command precludes the use of
412 regular class- and instance variables\&. It further precludes the use of
413 \fBmethod-introspection\fR as well, as this make use of generated
414 instance-variables\&.
415 .sp
416 If class- and/or instance-variable have to be used in
417 conjunction with an external C type, simply create and use a class- or
418 instance-variable with that type\&.
419 .sp
420 The result of the command is the empty string\&.
421 .PP
422 .SS "CLASS LIFETIME MANAGEMENT"
423 .TP
424 \fBclassconstructor\fR \fIbody\fR
425 This command specifies a C code block surrounding the initialization
426 of the class variables, i\&.e\&. the fields of the class structure\&.
427 \fINote\fR that allocation and release of the class structure itself
428 is done by the system andf not the responsibility of the user\&.
429 .sp
430 For the initialization (and release) of a class variable it is
431 recommended to use the \fIconstructor\fR and \fIdestructor\fR
432 arguments of the variable's definition (See command
433 \fBclassvariable\fR) for this instead of using a separate
434 \fBclassconstructor\fR\&.
435 .sp
436 This is an optional command\&. Using it more than once is allowed
437 too and each use will add another C code fragment to use during
438 construction\&. I\&.e\&. multiple calls aggregate\&.
439 .sp
440 The C code blocks of multiple calls (including the constructors
441 of classvariable definitions) are executed in order of specification\&.
442 .sp
443 The result of the command is the empty string\&.
444 .sp
445 The C code in \fIbody\fR has access to the following
446 environment:
447 .RS
448 .TP
449 \fBinterp\fR
450 Pointer to the Tcl interpreter (Tcl_Interp*) the
451 class structure will be associated with\&. It enables the generation
452 of a Tcl error message should construction fail\&.
453 .TP
454 \fBclass\fR
455 Pointer to the class structure to initialize\&.
456 .TP
457 error
458 A C code label the constructor can jump to should it have
459 to signal a construction failure\&. It is the responsibility of the
460 constructor to release any variables already initialized before
461 jumping to this label\&. This also why the 'execution in order of
462 specification' is documented and can be relied on\&. It gives us the
463 knowledge which other constructors have already been run and
464 initialized what other fields\&.
465 .RE
466 .TP
467 \fBclassdestructor\fR \fIbody\fR
468 This command specifies a C code block surrounding the release of the
469 class variables, i\&.e\&. the fields of the class structure\&.
470 \fINote\fR that allocation and release of the class structure itself
471 is done by the system and not the responsibility of the user\&.
472 .sp
473 For the initialization (and release) of a class variable it is
474 recommended to use the \fIconstructor\fR and \fIdestructor\fR
475 arguments of the variable's definition (See command
476 \fBclassvariable\fR) for this instead of using a separate
477 \fBclassconstructor\fR\&.
478 .sp
479 This is an optional command\&. Using it more than once is allowed
480 too and each use will add another C code fragment to use during
481 construction\&. I\&.e\&. multiple calls aggregate\&.
482 .sp
483 The C code blocks of multiple calls (including the constructors
484 of class variable definitions) are executed in order of specification\&.
485 .sp
486 The result of the command is the empty string\&.
487 .sp
488 The C code in \fIbody\fR has access to the same
489 environment as the class constructor code blocks\&.
490 .PP
491 .SS "INSTANCE LIFETIME MANAGEMENT"
492 .TP
493 \fBconstructor\fR \fIbody\fR ?\fIpostbody\fR?
494 This command specifies a C code block surrounding the initialization
495 of the instance variables, i\&.e\&. the fields of the instance structure\&.
496 \fINote\fR that allocation and release of the instance structure
497 itself is done by the system and not the responsibility of the user\&.
498 \fIOn the other hand\fR, if an external \fBtype\fR was specified
499 for the instance structure, then instance variables are not possible,
500 and the system has no knowledge of the type's structure\&. In that case
501 it is the responsibility of the \fIbody\fR to allocate and free the
502 structure itself too\&.
503 .sp
504 For the initialization (and release) of an instance variable it
505 is recommended to use the \fIconstructor\fR and \fIdestructor\fR
506 arguments of the variable's definition (See command \fBinsvariable\fR)
507 for this instead of using a separate \fBconstructor\fR\&.
508 .sp
509 This is an optional command\&. Using it more than once is allowed
510 too and each use will add another C code fragment to use during
511 construction\&. I\&.e\&. multiple calls aggregate\&.
512 .sp
513 The C code blocks of multiple calls (including the constructors
514 of instance variable definitions) are executed in order of specification\&.
515 .sp
516 The result of the command is the empty string\&.
517 .sp
518 The C code in \fIbody\fR has access to the following
519 environment:
520 .RS
521 .TP
522 \fBinterp\fR
523 Pointer to the Tcl interpreter (Tcl_Interp*) the
524 instance structure will be associated with\&. It enables the generation
525 of a Tcl error message should construction fail\&.
526 .TP
527 \fBinstance\fR
528 Pointer to the instance structure to initialize\&.
529 .TP
530 error
531 A C code label the constructor can jump to should it have
532 to signal a construction failure\&. It is the responsibility of the
533 constructor to release any variables already initialized before
534 jumping to this label\&. This also why the 'execution in order of
535 specification' is documented and can be relied on\&. It gives us the
536 knowledge which other constructors have already been run and
537 initialized what other fields\&.
538 .RE
539 .sp
540 The C code in \fIpostbody\fR is responsible for construction
541 actions to be done after the primary construction was done and the
542 Tcl-level instance command was successfully created\&. It has access to
543 a slightly different environment:
544 .RS
545 .TP
546 \fBinterp\fR
547 Pointer to the Tcl interpreter (Tcl_Interp*) the
548 instance structure will be associated with\&. It enables the generation
549 of a Tcl error message should construction fail\&.
550 .TP
551 \fBinstance\fR
552 Pointer to the instance structure to initialize\&.
553 .TP
554 \fBcmd\fR
555 The Tcl_Command token of the Tcl-level instance
556 command\&.
557 .TP
558 \fBfqn\fR
559 The fully qualified name of the instance command,
560 stored in a Tcl_Obj*\&.
561 .RE
562 .TP
563 \fBdestructor\fR \fIbody\fR
564 This command specifies a C code block surrounding the release of the
565 instance variables, i\&.e\&. the fields of the instance structure\&.
566 \fINote\fR that allocation and release of the instance structure
567 itself is done by the system and not the responsibility of the user\&.
568 \fIOn the other hand\fR, if an external \fBtype\fR was specified
569 for the instance structure, then instance variables are not possible,
570 and the system has no knowledge of the type's structure\&. In that case
571 it is the responsibility of the \fIbody\fR to allocate and free the
572 structure itself too\&.
573 .sp
574 For the initialization (and release) of an instance variable it
575 is recommended to use the \fIconstructor\fR and \fIdestructor\fR
576 arguments of the variable's definition (See command \fBinsvariable\fR)
577 for this instead of using a separate \fBconstructor\fR\&.
578 .sp
579 This is an optional command\&. Using it more than once is allowed
580 too and each use will add another C code fragment to use during
581 construction\&. I\&.e\&. multiple calls aggregate\&.
582 .sp
583 The C code blocks of multiple calls (including the constructors
584 of instance variable definitions) are executed in order of specification\&.
585 .sp
586 The result of the command is the empty string\&.
587 .sp
588 The C code in \fIbody\fR has access to the following
589 environment:
590 .RS
591 .TP
592 \fBinstance\fR
593 Pointer to the instance structure to release\&.
594 .RE
595 .PP
596 .SS "CLASS VARIABLES AND METHODS"
597 .TP
598 \fBclassvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
599 This command specifies a field in the class structure of the class\&.
600 Multiple fields can be specified, and are saved in the order
601 specified\&.
602 .sp
603 \fIAttention:\fR Specification of a class variable precludes
604 the use of an external C \fBtype\fR for the instance structure\&.
605 .sp
606 \fIAttention:\fR Specification of a class variable
607 automatically causes the definition of an instance variable named
608 \fBclass\fR, pointing to the class structure\&.
609 .sp
610 Beyond the basic \fIname\fR and C type of the new variable the
611 definition may also contain a \fIcomment\fR describing it, and C code
612 blocks to initialize and release the variable\&.
613 These are effectively local forms of the commands
614 \fBclassconstructor\fR and \fBclassdestructor\fR\&. Please read their
615 descriptions for details regarding the C environment available to the
616 code\&.
617 .sp
618 The comment, if specified will be embedded into the generated C
619 code for easier cross-referencing from generated "\fI\&.c\fR" file to
620 class specification\&.
621 .TP
622 \fBclassmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
623 This command specifies a class method and the C code block
624 implementing its functionality\&. This is the first of three forms\&. The
625 method is specified like a \fBcritcl::ccommand\fR, with a fixed set of
626 C-level arguments\&. The \fIbody\fR has to perform everything
627 (i\&.e\&. argument extraction, checking, result return, and of course the
628 actual functionality) by itself\&.
629 .sp
630 For this the \fIbody\fR has access to
631 .RS
632 .TP
633 \fBclass\fR
634 Pointer to the class structure\&.
635 .TP
636 \fBinterp\fR
637 Pointer to the Tcl interpreter (Tcl_Interp*) the
638 class structure is associated with
639 .TP
640 \fBobjc\fR
641 The number of method arguments\&.
642 .TP
643 \fBobjv\fR
644 The method arguments, as C array of Tcl_Obj pointers\&.
645 .RE
646 .IP
647 The \fIarguments\fR of the definition are only a human readable form
648 of the method arguments and syntax and are not used in the C code,
649 except as comments put into the generated code\&. Again, it is the
650 responsibility of the \fIbody\fR to check the number of arguments,
651 extract them, check their types, etc\&.
652 .TP
653 \fBclassmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
654 This command specifies a class method and the C code block
655 implementing its functionality\&. This is the second of three forms\&. The
656 method is specified like a \fBcritcl::cproc\fR\&.
657 Contrary to the first variant here the \fIarguments\fR are computer
658 readable, expected to be in the same format as the \fIarguments\fR of
659 \fBcritcl::cproc\fR\&. The same is true for the \fIresulttype\fR\&.
660 The system automatically generates a wrapper doing argument checking
661 and conversion, and result conversion, like for \fBcritcl::cproc\fR\&.
662 .sp
663 The \fIbody\fR has access to
664 .RS
665 .TP
666 \fBclass\fR
667 Pointer to the class structure\&.
668 .TP
669 \fBinterp\fR
670 Pointer to the Tcl interpreter (Tcl_Interp*) the
671 class structure is associated with
672 .TP
673 \&.\&.\&.
674 All \fIarguments\fR under their specified names and C types
675 as per their definition\&.
676 .RE
677 .TP
678 \fBclassmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
679 This command specifies a class method and the C code block
680 implementing its functionality\&. This is the third and last of three
681 forms\&.
682 .sp
683 The class method is implemented by the external function
684 \fIfunname\fR, i\&.e\&. a function which is declared outside of the class
685 code itself, or in a \fBsupport\fR block\&.
686 .sp
687 It is assumed that the first four arguments of that function
688 represent the parameters
689 .RS
690 .TP
691 \fBclass\fR
692 Pointer to the class structure\&.
693 .TP
694 \fBinterp\fR
695 Pointer to the Tcl interpreter (Tcl_Interp*) the
696 class structure is associated with
697 .TP
698 \fBobjc\fR
699 The number of method arguments\&.
700 .TP
701 \fBobjv\fR
702 The method arguments, as C array of Tcl_Obj pointers\&.
703 .RE
704 .IP
705 Any additional arguments specified will be added after these and are
706 passed into the C code as is, i\&.e\&. are considered to be C expressions\&.
707 .PP
708 .SS "INSTANCE VARIABLES AND METHODS"
709 .TP
710 \fBinsvariable\fR \fIctype\fR \fIname\fR ?\fIcomment\fR? ?\fIconstructor\fR? ?\fIdestructor\fR?
711 This command specifies a field in the instance structure of the class\&.
712 Multiple fields can be specified, and are saved in the order
713 specified\&.
714 .sp
715 \fIAttention:\fR Specification of an instance variable
716 precludes the use of an external C \fBtype\fR for the instance
717 structure\&.
718 .sp
719 \fIAttention:\fR Specification of an instance variable
720 automatically causes the definition of an instance variable of type
721 \fBTcl_Command\fR, and named \fBcmd\fR, holding the token of the
722 instance command, and the definition of an instance method named
723 \fBdestroy\fR\&. This implicit instance variable is managed by the
724 system\&.
725 .sp
726 Beyond the basic \fIname\fR and C type of the new variable the
727 definition may also contain a \fIcomment\fR describing it, and C code
728 blocks to initialize and release the variable\&.
729 These are effectively local forms of the commands \fBconstructor\fR
730 and \fBdestructor\fR\&. Please read their descriptions for details
731 regarding the C environment available to the code\&.
732 .sp
733 The comment, if specified will be embedded into the generated C
734 code for easier cross-referencing from generated "\fI\&.c\fR" file to
735 class specification\&.
736 .TP
737 \fBmethod\fR \fIname\fR \fBcommand\fR \fIarguments\fR \fIbody\fR
738 This command specifies an instance method and the C code block
739 implementing its functionality\&. This is the first of three forms\&. The
740 method is specified like a \fBcritcl::ccommand\fR, with a fixed set of
741 C-level arguments\&. The \fIbody\fR has to perform everything
742 (i\&.e\&. argument extraction, checking, result return, and of course the
743 actual functionality) by itself\&.
744 .sp
745 For this the \fIbody\fR has access to
746 .RS
747 .TP
748 \fBinstance\fR
749 Pointer to the instance structure\&.
750 .TP
751 \fBinterp\fR
752 Pointer to the Tcl interpreter (Tcl_Interp*) the
753 instance structure is associated with
754 .TP
755 \fBobjc\fR
756 The number of method arguments\&.
757 .TP
758 \fBobjv\fR
759 The method arguments, as C array of Tcl_Obj pointers\&.
760 .RE
761 .IP
762 The \fIarguments\fR of the definition are only a human readable form
763 of the method arguments and syntax and are not used in the C code,
764 except as comments put into the generated code\&. Again, it is the
765 responsibility of the \fIbody\fR to check the number of arguments,
766 extract them, check their types, etc\&.
767 .TP
768 \fBmethod\fR \fIname\fR \fBproc\fR \fIarguments\fR \fIresulttype\fR \fIbody\fR
769 This command specifies an instance method and the C code block
770 implementing its functionality\&. This is the second of three
771 forms\&. The method is specified like a \fBcritcl::cproc\fR\&.
772 Contrary to the first variant here the \fIarguments\fR are computer
773 readable, expected to be in the same format as the \fIarguments\fR of
774 \fBcritcl::cproc\fR\&. The same is true for the \fIresulttype\fR\&.
775 The system automatically generates a wrapper doing argument checking
776 and conversion, and result conversion, like for \fBcritcl::cproc\fR\&.
777 .sp
778 The \fIbody\fR has access to
779 .RS
780 .TP
781 \fBinstance\fR
782 Pointer to the instance structure\&.
783 .TP
784 \fBinterp\fR
785 Pointer to the Tcl interpreter (Tcl_Interp*) the
786 instance structure is associated with
787 .TP
788 \&.\&.\&.
789 All \fIarguments\fR under their specified names and C types
790 as per their definition\&.
791 .RE
792 .TP
793 \fBmethod\fR \fIname\fR \fBas\fR \fIfunname\fR ?\fIarg\fR\&.\&.\&.?
794 This command specifies an instance method and the C code block
795 implementing its functionality\&. This is the third and last of three
796 forms\&.
797 .sp
798 The instance method is implemented by the external function
799 \fIfunname\fR, i\&.e\&. a function which is declared outside of the instance
800 code itself, or in a \fBsupport\fR block\&.
801 .sp
802 It is assumed that the first four arguments of that function
803 represent the parameters
804 .RS
805 .TP
806 \fBinstance\fR
807 Pointer to the instance structure\&.
808 .TP
809 \fBinterp\fR
810 Pointer to the Tcl interpreter (Tcl_Interp*) the
811 instance structure is associated with
812 .TP
813 \fBobjc\fR
814 The number of method arguments\&.
815 .TP
816 \fBobjv\fR
817 The method arguments, as C array of Tcl_Obj pointers\&.
818 .RE
819 .IP
820 Any additional arguments specified will be added after these and are
821 passed into the C code as is, i\&.e\&. are considered to be C expressions\&.
822 .TP
823 \fBmethod_introspection\fR
824 This command generates one class- and one instance-method both of
825 which will return a list of the instance methods of the class, and
826 supporting structures, like the function to compute the information,
827 and a class variable caching it\&.
828 .sp
829 The two methods and the class variable are all named
830 \fBmethods\fR\&.
831 .PP
832 .SS "CONTEXT DEPENDENT INTERACTIONS"
833 This section documents the various interactions between the
834 specification commands\&. While these are are all documented with the
835 individual commands here they are pulled together to see at a glance\&.
836 .IP [1]
837 If you are using the command \fBtype\fR to specify an external
838 C type to use for the instance structure you are subject to
839 the following constraints and rules:
840 .RS
841 .IP [1]
842 You cannot define your own instance variables\&.
843 .IP [2]
844 You cannot define your own class variables\&.
845 .IP [3]
846 You cannot use \fBmethod_introspection\fR\&.
847 .IP [4]
848 You have to allocate and release the instance structure on your
849 own, through \fBconstructor\fR and \fBdestructor\fR code blocks\&.
850 .RE
851 .IP [2]
852 If you declare class variables you are subject to the
853 following constraints and rules:
854 .RS
855 .IP [1]
856 You cannot use \fBtype\fR\&.
857 .IP [2]
858 The system generates an instance variable \fBclass\fR for
859 you, which points from instance to class structure\&. This makes
860 you also subject to the rules below, for instance variables\&.
861 .RE
862 .IP [3]
863 If you declare instance variables (possibly automatic, see
864 above) you are subject to following constraints and rules:
865 .RS
866 .IP [1]
867 You cannot use \fBtype\fR\&.
868 .IP [2]
869 The system generates and manages an instance variable
870 \fBcmd\fR for you, which holds the Tcl_Command token
871 of the instance command\&.
872 .IP [3]
873 The system generates an instance method \fBdestroy\fR for
874 you\&.
875 .IP [4]
876 The system manages allocation and release of the instance
877 structure for you\&. You have to care only about the instance
878 variables themselves\&.
879 .RE
880 .PP
881 .SH EXAMPLE
882 The example shown below is the specification of queue data structure,
883 with most of the method implementations and support code omitted to
884 keep the size down\&.
885 .PP
886 The full implementation can be found in the directory
887 "\fIexamples/queue\fR" of the critcl source distribution/repository\&.
888 .CS
889
890
891 package require Tcl 8\&.6
892 package require critcl 3\&.2
893
894 critcl::buildrequirement {
895 package require critcl::class ; # DSL, easy spec of Tcl class/object commands\&.
896 }
897
898 critcl::cheaders util\&.h
899
900 critcl::class::define ::queuec {
901 include util\&.h
902
903 insvariable Tcl_Obj* unget {
904 List object unget elements
905 } {
906 instance->unget = Tcl_NewListObj (0,NULL);
907 Tcl_IncrRefCount (instance->unget);
908 } {
909 Tcl_DecrRefCount (instance->unget);
910 }
911
912 insvariable Tcl_Obj* queue {
913 List object holding the main queue
914 } {
915 instance->queue = Tcl_NewListObj (0,NULL);
916 Tcl_IncrRefCount (instance->queue);
917 } {
918 Tcl_DecrRefCount (instance->queue);
919 }
920
921 insvariable Tcl_Obj* append {
922 List object holding new elements
923 } {
924 instance->append = Tcl_NewListObj (0,NULL);
925 Tcl_IncrRefCount (instance->append);
926 } {
927 Tcl_DecrRefCount (instance->append);
928 }
929
930 insvariable int at {
931 Index of next element to return from the main queue
932 } {
933 instance->at = 0;
934 }
935
936 support {\&.\&.\&. queue_peekget, queue_size, etc\&.}
937
938 method clear {} {\&.\&.\&.}
939 method destroy {\&.\&.\&.}
940
941 method get as queue_peekget 1
942 method peek as queue_peekget 0
943
944 method put {item \&.\&.\&.}
945
946 method size {} {
947 if ((objc != 2)) {
948 Tcl_WrongNumArgs (interp, 2, objv, NULL);
949 return TCL_ERROR;
950 }
951
952 Tcl_SetObjResult (interp, Tcl_NewIntObj (queue_size (instance, NULL, NULL, NULL)));
953 return TCL_OK;
954 }
955
956 method unget {item} {\&.\&.\&.}
957 }
958
959 package provide queuec 1
960
961 .CE
962 .SH AUTHORS
963 Andreas Kupries
964 .SH "BUGS, IDEAS, FEEDBACK"
965 This document, and the package it describes, will undoubtedly contain
966 bugs and other problems\&.
967 Please report such at \fIhttps://github\&.com/andreas-kupries/critcl\fR\&.
968 Please also report any ideas for enhancements you may have for either
969 package and/or documentation\&.
970 .SH KEYWORDS
971 C class, C code, C instance, C object, Embedded C Code, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, generate package, linker, on demand compilation, on-the-fly compilation
972 .SH CATEGORY
973 Glueing/Embedded C code
974 .SH COPYRIGHT
975 .nf
976 Copyright (c) 2011-2024 Andreas Kupries
977
978 .fi