Tcl Portable Runtime Library

Reading up on Subversion, I came across some references [L1 ] to the Apache Portable Runtime Library, which is described as follows:

APR is Apache's portability library, originally carved out of its server code as an attempt to separate the OS-specific bits from the OS-independent portions of the code. The result was a library that provides a generic API for performing operations that differ mildly—or wildly—from OS to OS.

My main reaction to this was "So what? We've got one of these too — perhaps even more portable" (cf. On What Platforms Does Tcl Run), but of course "XXX Portable Runtime Library" sounds a bit snazzier than libtcl.so...

Therefore I think it would be a good idea to collect some information about using Tcl as a C library, but since I haven't had much practical experience in the matter, I'm hoping others can lend a hand in fleshing it out, — Lars H, 2007-11-11.


Features available from the Tcl C library include...

Low level features (meaning roughly that if you really need to, it would probably be possible to extract the implementation of these from the rest of the library)

Hashes
Keys can be strings, integers, or pointers. Entries are pointers. Custom hashing functions can, but doesn't have to, be supplied.
DStrings
Efficient C-style strings whose memory allocation grow as needed — no more buffer overflows!
regexps
A Unicode-aware and fast RE engine.
libtommath (as of 8.5)
Arbitrary-precision arithmetic

Medium level features (meaning roughly you can use them without worrying about the big picture)

Tcl_Objs, lists, and dicts
Nestable generic data containers.
encodings
Convert between Unicode and other character encodings.
Event loop
[write something about it]
after
equivalent to sleep(), but more accurate (time is expressed in ms, not in seconds)
Threads
Many of the thread APIs are thoroughly inconsistent across platforms, but Tcl hides that.

High level features

channels
Attached to files, pipes, sockets, serial ports, or whatsnot. Stackable. [Probably have many more features]
clock
Date and time format handling.
FileSystems
Native or VFS, it's all the same. Support for varying file path syntaxes.
Tcl interpreter
You can have none, one, or several; create or destroy dynamically.

[List incomplete. Categorization may be wrong.]

[Would be nice to point out areas where Tcl hides inconsistent behaviour on different platforms. Threads, perhaps?]

See also Tk Portable Runtime Library.