|
NAMEcritcl::callback - CriTcl C-level Callback UtilitiesSYNOPSISpackage require Tcl 8.4package require critcl ?3.1? package require critcl::callback ?0.1? critcl_callback_p critcl_callback_new interp objc objv nargs void critcl_callback_extend callback argument void critcl_callback_destroy callback int critcl_callback_invoke callback objc objv DESCRIPTIONC Runtime In Tcl, or CriTcl , is a system for compiling C code embedded in Tcl on the fly and either loading the resulting objects into Tcl for immediate use or packaging them for distribution. Use CriTcl to improve performance by rewriting in C those routines that are performance bottlenecks.This document is the reference manpage for the critcl::callback package. This package provides, via a stubs API table, data structures and functions to manage callbacks from C to Tcl. The package has no Tcl-level facilities. Its intended audience are mainly developers wishing to write Tcl packages with embedded C code who have to invoke user-specified command (prefixes) in Tcl. This package resides in the Support Package Layer of CriTcl. +----------------+ |Applications | | critcl | | critcl::app | +----------------+ +----------------+ |Core Packages | | critcl | | critcl::util | +----------------+ *================* |Support Packages| | stubs::* | | md5, platform | | ... | *================* APIThe package API consist of one opaque data structure (critcl_callback_p) and four functions operating on the same. These functions are
EXAMPLESSIMPLE CALLBACKThe example here shows the important parts of using the functions of this package for a simple callback which is invoked with a single argument, some kind of data to hand to the Tcl level.// Create the callback with interpreter and command prefix in // oc/ov, plus space for the argument critcl_callback_p cb = critcl_callback_new (interp, oc, ov, 1); // Invoke the callback somewhere in the C package using this one, // with Tcl_Obj* data holding the information to pass up. critcl_callback_invoke (cb, 1, &data); // At the end of the lifetime, release the callback. critcl_callback_destroy (cb); Using the sequence above as is, creating and destroying the callback each time it is invoked will yield very poor performance and lots of undesirable memory churn. MULTIPLE METHODSWhile we can use the methodology of the previous section when a single (Tcl-level) callback is invoked from different places in C, with different methods, simply having another argument slot and filling it an invokation time with the method object, a second methodology is open to us due to critcl_callback_extend.// Create one callback manager per different method the callback // will be used with. Fill the first of the two declared arguments // with the different methods. critcl_callback_p cb_a = critcl_callback_new (interp, oc, ov, 2); critcl_callback_p cb_b = critcl_callback_new (interp, oc, ov, 2); critcl_callback_extend (cb_a, Tcl_NewStringObj ("method1", -1)); critcl_callback_extend (cb_b, Tcl_NewStringObj ("method2", -1)); // After the extension we have one free argument left, for use in // the invokations. critcl_callback_invoke (cb_a, 1, &dataX); critcl_callback_invoke (cb_b, 1, &dataY); // At the end release both managers again critcl_callback_destroy (cb_a); critcl_callback_destroy (cb_b); AUTHORSAndreas KupriesBUGS, IDEAS, FEEDBACKThis document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such at https://github.com/andreas-kupries/critcl. Please also report any ideas for enhancements you may have for either package and/or documentation.KEYWORDSC code, Embedded C Code, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, generate package, linker, on demand compilation, on-the-fly compilationCATEGORYGlueing/Embedded C codeCOPYRIGHTCopyright (c) 2011-2018 Andreas Kupries
Visit the GSP FreeBSD Man Page Interface. |