|
NAMEcritcl::emap - CriTcl Utilities: Enum en- and decodingSYNOPSISpackage require Tcl 8.4package require critcl ?3.1.11? package require critcl::emap ?1.2? ::critcl::emap::def name definition ?-nocase? ?-mode mode? 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::emap package. This package provides convenience commands for advanced functionality built on top of both critcl core and package critcl::iassoc. C level libraries often use enumerations or integer values to encode information, like the state of a system. Tcl bindings to such libraries now have the task of converting a Tcl representation, i.e. a string into such state, and back. Note here that the C-level information has to be something which already exists. The package does not create these values. This is in contrast to the package critcl::enum which creates an enumeration based on the specified symbolic names. This package was written to make the declaration and management of such enumerations and their associated conversions functions easy, hiding all attendant complexity from the user. Its intended audience are mainly developers wishing to write Tcl packages with embedded C code. This package resides in the Core Package Layer of CriTcl. +----------------+ |Applications | | critcl | | critcl::app | +----------------+ *================* |Core Packages | | critcl | | critcl::util | *================* +----------------+ |Support Packages| | stubs::* | | md5, platform | | ... | +----------------+ API
int name_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result); The return value of the function is a Tcl error code, i.e. TCL_OK, TCL_ERROR, etc.
int name_encode_cstr (const char* state); The return value of the function is the encoded state, or -1 if the argument is not a vlaid state.
Tcl_Obj* name_decode (Tcl_Interp* interp, int state);
const char* name_decode_cstr (int state); The return value of the function is the C string for the state, or NULL if the state argument does not contain a valid state value.
EXAMPLEThe example shown below is the specification for the possible modes of entry (normal, no feedback, stars) used by the Tcl binding to the linenoise library.package require Tcl 8.5 package require critcl 3.1.11 critcl::buildrequirement { package require critcl::emap } critcl::emap::def hiddenmode { no 0 n 0 off 0 false 0 0 0 all 1 yes 1 y 1 on 1 true 1 1 1 stars 2 } -nocase # Declarations: hiddenmode.h # Encoder: int hiddenmode_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result); # Decoder: Tcl_Obj* hiddenmode_decode (Tcl_Interp* interp, int state); # ResultType: hiddenmode # ArgumentType: hiddenmode 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, Tcl Interp Association, bitmask, bitset, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, flags, generate package, linker, on demand compilation, on-the-fly compilation, singletonCATEGORYGlueing/Embedded C codeCOPYRIGHTCopyright (c) 2011-2018 Andreas Kupries
Visit the GSP FreeBSD Man Page Interface. |