Tcl_RegisterConfig(3)

πŸ“¦
version 9.0.3 Β· 2 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– Tcl_RegisterConfig β€” the manual page, but make it a group chat πŸ’–

okay bestie, so this is a page from the Tcl Library Procedures manual, and it's all about Tcl_RegisterConfig. it's giving "let me tuck my config info into my library and then let Tcl peek at it" energy. sit down, hydrate, we're doing this 🫢


✨ NAME ✨

Tcl_RegisterConfig β€” procedures to register embedded configuration information πŸ’…


✨ SYNOPSIS ✨

#include <tcl.h>

Tcl_RegisterConfig(interp, pkgName, configuration, valEncoding)

✨ ARGUMENTS ✨

  • Tcl_Interp *interp (in) β€” points at the interpreter that the embedded configuration info is getting registered for. Must not be NULL. like, ever. that's the whole vibe.
  • const char *pkgName (in) β€” the name of the package that's registering the embedded config, as an ASCII string. which lowkey means this info is in UTF-8 too. Must not be NULL. πŸ’€
  • const Tcl_Config *configuration (in) β€” a pointer to an array of Tcl_Config entries holding the info that's embedded in the library. Must not be NULL. the end of the array is signalled by either a key identical to NULL, or a key referring to the empty string. two ways to say goodbye, iconic 🌸
  • const char *valEncoding (in) β€” the name of the encoding used to store the configuration values, as an ASCII string. which again means this info is in UTF-8 too. Must not be NULL. 😭

✨ DESCRIPTION ✨

so the function we're talking about has its whole base in TIP 59, and it gives extensions support for embedding configuration information into their library, plus the generation of a Tcl-level interface for querying all that info. slay πŸŽ€

to embed configuration info into their library, an extension has to define a non-volatile array of Tcl_Config entries in one of its source files, and then call Tcl_RegisterConfig to register that information. that's it, that's the move ✨

Tcl_RegisterConfig takes four arguments:

  1. a reference to the interpreter we're registering the info with,
  2. the name of the package registering its configuration information,
  3. a pointer to an array of structures, and
  4. a string declaring the encoding used by the configuration values.

The string valEncoding contains the name of an encoding known to Tcl. All these names use only characters in the ASCII subset of UTF-8, and are thus implicitly in the UTF-8 encoding. It is expected that keys are legible English text, and therefore using the ASCII subset of UTF-8. in other words, they're expected to be in UTF-8 too, no cap. The values associated with the keys can be any string however. for these, the contents of valEncoding define which encoding was used to represent the characters of the strings πŸ¦‹

Each element of the configuration array refers to two strings: the key, and the value associated with that key. The end of the array is signalled by either an empty key or a key identical to NULL. The function makes no copy of the configuration array. This means the caller has to make sure that the memory holding this array is never released. This is the meaning behind the word non-volatile used earlier β€” that's what it was doing the whole time, main character behaviour fr fr πŸ‘‘

the easiest way to accomplish this is to define a global static array of Tcl_Config entries. See the file generic/tclPkgConfig.c in the sources of the Tcl core for an example πŸ’–

When called, Tcl_RegisterConfig will:

  1. create a namespace having the provided pkgName, if not yet existing. 🌈
  2. create the command pkgconfig in that namespace, and link it to the provided information, so that the keys from configuration and their associated values can be retrieved through calls to pkgconfig. ✨

The command pkgconfig will provide two subcommands, list and get:

  • ::pkgName::pkgconfig list Returns a list containing the names of all defined keys. πŸ“‹
  • ::pkgName::pkgconfig get key Returns the configuration value associated with the specified key. πŸ”

✨ TCL_CONFIG ✨

The Tcl_Config structure contains the following fields:

typedef struct {
    const char *key;
    const char *value;
} Tcl_Config;

✨ KEYWORDS ✨

embedding, configuration, library πŸ’œ


okay that's the whole page, you ate it, go register some config bestie πŸ’…

this lil masterpiece came out with Tcl 8.4, and it lives as Tcl_RegisterConfig(3). bye babe, go touch some source files πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from