1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
# callback.tcl -
#
# C support package for the management of callbacks into Tcl.
#
# __Note__, this package does not expose anything at Tcl level. It
# only provides stubs (i.e. functions) and data structures providing
# C-level callback managers.
package provide critcl::callback 1.1
package require critcl 3.2
critcl::buildrequirement {
package require critcl::cutil ;# assertions, allocation support, tracing
}
if {![critcl::compiling]} {
error "Unable to build `critcl::callback`, no proper compiler found."
}
# # ## ### ##### ######## #############
## Build configuration
# (1) Assertions, and tracing
# (2) Debugging symbols, memory tracking
critcl::cutil::assertions off
critcl::cutil::tracer off
#critcl::debug symbols
#Activate when in need of memory debugging - Valgrind is an alternative
#critcl::debug symbols memory
critcl::config lines 1
critcl::config trace 0
# # ## ### ##### ######## #############
## Administrivia
critcl::license \
{Andreas Kupries} \
{Under a BSD license.}
critcl::summary \
{Critcl utility package providing functions and structures to manage callbacks into Tcl, from C}
critcl::description \
{Part of Critcl}
critcl::subject critcl callbacks {management of callbacks}
critcl::subject {Tcl callbacks from C}
# # ## ### ##### ######## #############
## Implementation.
critcl::cutil::alloc
# # ## ### ##### ######## #############
critcl::cheaders c/*.h
critcl::csources c/*.c
# Stubs definitions.
critcl::api header c/callback.h
# Create a new callback instance with prefix objc/objv and space for
# `nargs` arguments. The callback keeps the objv elements as is and
# signal this by incrementing their reference counts. The callback
# will be run in the provided interpreter, at the global level and
# namespace.
critcl::api function critcl_callback_p critcl_callback_new {
Tcl_Interp* interp
Tcl_Size objc
Tcl_Obj** objv
Tcl_Size nargs
}
# Modify the specified callback by placing the argument into the first
# free argument slot. This extends the prefix part of the callback,
# and reduces the argument part, by one.
critcl::api function void critcl_callback_extend {
critcl_callback_p callback
Tcl_Obj* argument
}
# Release all memory associated with the callback instance. For the
# objv elements saved during construction (see above) this is signaled
# by decrementing their reference counts.
critcl::api function void critcl_callback_destroy {
critcl_callback_p callback
}
# Invoke the callback using the objc/objv elements as the arguments.
# The operation will panic or crash if more arguments are provided
# than the callback has space for. See the `nargs` parameter of the
# constructor function above. Less arguments then constructed for
# however are ok.
critcl::api function int critcl_callback_invoke {
critcl_callback_p callback
Tcl_Size objc
Tcl_Obj** objv
}
##
return
|