2
# # ## ### ##### ######## ############# #####################
3
# Pragmas for MetaData Scanner.
4
# @mdgen OWNER: iassoc.h
6
# CriTcl Utility Commands. Specification of a C function and structure
7
# associated with an interpreter made easy.
9
package provide critcl::iassoc 1.0.1
11
# # ## ### ##### ######## ############# #####################
14
package require Tcl 8.4 ; # Min supported version.
15
package require critcl 3.1 ; # Need 'meta?' to get the package name.
16
package require critcl::util ; # Use the package's Get/Put commands.
18
namespace eval ::critcl::iassoc {}
20
# # ## ### ##### ######## ############# #####################
21
## API: Generate the declaration and implementation files for the iassoc.
23
proc ::critcl::iassoc::def {name arguments struct constructor destructor} {
25
critcl::at::incrt $arguments ; set sloc [critcl::at::get*]
26
critcl::at::incrt $struct ; set cloc [critcl::at::get*]
27
critcl::at::incrt $constructor ; set dloc [critcl::at::get]
29
set struct $sloc$struct
30
set constructor $cloc$constructor
31
set destructor $dloc$destructor
35
# - name of the C function which will provide access to the
36
# structure. This name, with a fixed prefix is also used to
37
# identify the association within the interpreter, and for
38
# the structure's type.
40
# - C code declaring the structure's contents.
41
# - C code executed to initialize the structure.
42
# - C code executed to destroy the structure.
44
# Note that this is, essentially, a singleton object, without
47
# Pull the package we are working on out of the system.
49
set package [critcl::meta? name]
51
#puts "%%% Pkg |$package|"
52
#puts "%%% Name |$name|"
56
set stem ${package}_iassoc_${name}
58
set label critcl::iassoc/p=$package/a=$name
61
if {[llength $arguments]} {
62
foreach {t v} $arguments {
66
set arguments ", [join $alist {, }]"
67
set anames ", [join $anames {, }]"
70
lappend map @package@ $package
71
lappend map @name@ $name
72
lappend map @stem@ $stem
73
lappend map @label@ $label
74
lappend map @type@ $type
75
lappend map @struct@ $struct
76
lappend map @argdecls@ $arguments
77
lappend map @argnames@ $anames
78
lappend map @constructor@ $constructor
79
lappend map @destructor@ $destructor
82
set header [file join [critcl::cache] $hdr]
83
set template [Template iassoc.h]
85
#puts T=[string length $template]
87
file mkdir [critcl::cache]
88
critcl::util::Put $header [string map $map $template]
90
critcl::ccode "#include <$hdr>"
94
proc ::critcl::iassoc::Template {path} {
96
set path $selfdir/$path
98
return [critcl::util::Get $path]
101
# # ## ### ##### ######## ############# #####################
103
# Internal: Namespace holding the specification commands and related
104
# state. Treat like a sub-package, with a proper API.
106
# # ## ### ##### ######## ############# #####################
108
namespace eval ::critcl::iassoc::spec {}
110
# # ## ### ##### ######## ############# #####################
112
# # ## ### ##### ######## ############# #####################
115
namespace eval ::critcl::iassoc {
116
variable selfdir [file dirname [file normalize [info script]]]
119
# # ## ### ##### ######## ############# #####################
122
namespace eval ::critcl::iassoc {
124
catch { namespace ensemble create }
127
# # ## ### ##### ######## ############# #####################