Skip to content

Instantly share code, notes, and snippets.

View nat-418's full-sized avatar

Nat nat-418

View GitHub Profile
@nat-418
nat-418 / space2escape.tcl
Created November 14, 2021 13:11
Replace whitespace characters with escape codes in Tcl
# Replace whitespace characters with their escape codes
#
# @param str String containing some whitespace
# @return New string with escapes instead of whitespace
proc space2escape str {
set escapes {
\b \\b
\f \\f
\n \\n
\r \\r
@nat-418
nat-418 / static-variables.tcl
Last active November 14, 2021 08:26
Using Tcl's uplevel command to create a static variable control structure
# This is an example of using Tcl's uplevel to create new control structures,
# and can be found on page 59 of "Exploring Expect" by Don Libes.
# Like variables declared global, variables declared static are
# accessible from other procedures. However, the same static variable
# cannot be accessed by procedures in different files.
#
# @param args The aguments to static are the same as global.
# @return Void, the side effect is manipulating the static state array.
proc static {args} {
set unique [info script]
@nat-418
nat-418 / making-tcl-packages-and-modules.md
Last active November 5, 2022 23:13
How to make Tcl packages and modules

How to make Tcl packages and modules

Tcl provides a package system that allows Tclers to share code. This package system supports two different formats that serve different use-cases:

  1. The "package" or "8.5" format is more verbose, but allows package authors more flexibility through the pkgIndex.tcl file. This is designed for complex, multi-file programs.
@nat-418
nat-418 / making-tcl-starpacks.md
Last active November 25, 2021 23:51
How to make standalone native binaries from Tcl scripts.

How to make Tcl Starpacks

Tcl scripts can be made into standalone executables for various platforms in what are called Starpacks. Statically linking Tcl libraries in a Starpack helps make Tcl programs more portable.

Building a Starpack requires:

  1. The sdx tool.
  2. A TclKit runtime for your operating system and architecture.