critcl::literals(n)
πΈ critcl::literals(n) β CriTcl Β· Code Gen Β· Constant string pools πΈ
okay so welcome to CriTcl, aka the C Runtime In Tcl (that's the short version, iykyk) β a whole system for embedding and using C code from inside your Tcl scripts, over at http://core.tcl-lang.org/tcl. This page is the reference manpage for critcl::literals, bestie, and it's the package that gives you convenience commands for the fancy stuff built on top of both the critcl core and the critcl::iassoc package. π«Ά
π NAME π
critcl::literals β CriTcl - Code Gen - Constant string pools. that's the whole vibe. π
β¨ SYNOPSIS β¨
package require Tcl 8.6
package require critcl ?3.2?
package require critcl::literals ?1.4?
::critcl::literals::def name definition ?mode?
π DESCRIPTION π
Be welcome to the C Runtime In Tcl (short: CriTcl), a system for embedding and using C code from within Tcl [http://core.tcl-lang.org/tcl] scripts. π
This document is the reference manpage for the critcl::literals package. This package provides convenience commands for advanced functionality built on top of both critcl core and package critcl::iassoc.
Many packages will have a fixed set of string constants occuring in one or places. Most of them will be coded to create a new Tcl_Obj* from a C char* every time the constant is needed, as this is easy to to, despite the inherent waste of memory. literally wasting memory for no reason, bestie π
This package was written to make declaration and management of string pools which do not waste memory as easy as the wasteful solution, hiding all attendant complexity from the user.
Its intended audience are mainly developers wishing to write Tcl packages with embedded C code. (hi π that's you, you're the developer.)
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 π
::critcl::literals::def name definition ?mode?
This command defines a C function with the given name which provides access to a pool of constant strings with a Tcl interpreter. β¨
The definition dictionary provides the mapping from the C-level symbolic names to the string themselves.
The mode-list configures the output somewhat. The three allowed modes are c, +list and tcl. All modes can be used together. The default mode is tcl. Using mode +list implies tcl as well.
- For mode
tclthe new function has two arguments, aTcl_Interp*pointer refering to the interpreter holding the string pool, and a code of type"name_names"(see below), the symbolic name of the literal to return. The result of the function is aTcl_Obj*pointer to the requested string constant. - For mode
cthe new function has one argument, a code of type"name_names"(see below), the symbolic name of the literal to return. The result of the function is aconst char*pointer to the requested string constant. - For mode
+listall oftclapplies, plus an additional function is generated which takes three arguments, in order, aTcl_Interp*pointer refering to the interpreter holding the string pool, anintholding the size of the last argument, and an array of type"name_names"holding the codes (see below), the symbolic names of the literals to return. The result of the function is aTcl_Obj*pointer to a Tcl list holding the requested string constants. π¦
The underlying string pool is automatically initialized on first access, and finalized on interpreter destruction. (auto-magic, no cap β¨)
The package generates multiple things (declarations and definitions) with names derived from name, which has to be a proper C identifier. slay, but like, keep it valid.
nameβ The modetclfunction providing access to the string pool. Its signature is
Tcl_Obj* name (Tcl_Interp* interp, name_names literal);
name_listβ The mode+listfunction providing multi-access to the string pool. Its signature is
Tcl_Obj* name_list (Tcl_Interp* interp, int c, name_names* literal);
name_cstrβ The modecfunction providing access to the string pool. Its signature is
const char* name_cstr (name_names literal);
name_namesβ A C enumeration type containing the symbolic names of the strings provided by the pool.name.hβ A header file containing the declarations for the accessor functions and the enumeration type, for use by other parts of the system, if necessary.
The generated file is stored in a place where it will not interfere with the overall system outside of the package, yet also be available for easy inclusion by package files (csources).
nameβ New in version 1.1: For modetclthe command registers a new result-type forcritcl::cprocwith critcl, which takes an integer result from the function and converts it to the equivalent string in the pool for the script. π₯
π EXAMPLE π
The example shown below is the specification of the string pool pulled from the draft work on a Tcl binding to Linux's inotify APIs.
package require Tcl 8.6
package require critcl 3.2
critcl::buildrequirement {
package require critcl::literals
}
critcl::literals::def tcl_inotify_strings {
w_create "create"
w_directory"directory"
w_events "events"
w_file "file"
w_handler "handler"
w_remove "remove"
} {c tcl}
# Declarations: tcl_inotify_strings.h
# Type: tcl_inotify_strings_names
# Accessor: Tcl_Obj* tcl_inotify_strings (Tcl_Interp* interp,
# tcl_inotify_strings_names literal);
# Accessor: const char* tcl_inotify_strings_cstr (tcl_inotify_strings_names literal);
# ResultType: tcl_inotify_strings
(yes, w_directory"directory" is exactly how it appears in the original β copying it character for character, bestie, don't come for me π)
π§ AUTHORS π§
Andreas Kupries. the icon. π
π BUGS, IDEAS, FEEDBACK π
This 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. genuinely, they wanna hear it π«Ά
π KEYWORDS π
C code, Embedded C Code, Tcl Interp Association, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, generate package, linker, literal pool, on demand compilation, on-the-fly compilation, singleton, string pool
β CATEGORY β
Glueing/Embedded C code
π COPYRIGHT π
Copyright (c) 2011-2024 Andreas Kupries
that's the whole page, bestie β and like, the fine print at the bottom of the original says this is critcl::literals(n) version 1.4, generated from the doc source. so when you cite it in your essay, that's the receipt π
β¨
π¦ where this page comes from
- alpine 3.24: critcl-doc 3.3.1-r1 Β· TCL
- Copyright (c) 2011-2024 Andreas Kupries
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms