1
[subsection {Having both C and Tcl functionality}]
3
Often enough only pieces of a package require recoding in C to boost
4
the whole system. Or, alternatively, the package in question consists
5
of a low-level layer C with a Tcl layer above encoding policies and
6
routing to the proper low-level calls, creating a nicer (high-level)
7
API to the low-level functionality, etc.
9
[para] For all of this we have to be able to write a package which
10
contains both C and Tcl, nevermind the fact the C parts are embedded
13
[para] The easiest way to structure such a package is to have several
14
files, each with a different duty. First, a [file .critcl] file
15
containing the embedded C, and second one or more [file .tcl] files
16
providing the Tcl parts.
18
Then use the [cmd critcl::tsources] command in the [file .critcl] file
19
to link the two parts together, declaring the [file .tcl] files as
20
necessary companions of the C part.
23
package require critcl
25
critcl::tsources your-companion.tcl ; # Companion file to use
27
... embedded C via critcl commands ...
30
With a declaration as shown above the companion file will be
31
automatically [cmd source]d when the C parts are made available, thus
32
making the Tcl parts available as well.