Tcl_SubstObj(3)

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

πŸ’– Tcl_SubstObj β€” bestie edition πŸ’–

okay so this is one of the Tcl Library Procedures, and we're about to do substitutions on Tcl values. it's giving subst but make it C. no cap. ✨


✨ NAME ✨

Tcl_SubstObj β€” perform substitutions on Tcl values πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <tcl.h>

Tcl_Obj *
Tcl_SubstObj(interp, objPtr, flags)

🌸 ARGUMENTS 🌸

  • Tcl_Interp *interp (in) β€” the interpreter where we're gonna run Tcl scripts and look up variables. if something goes wrong, the interpreter's result gets rewritten to hold an error message. so like, she tells you when it's bad. πŸ’…
  • Tcl_Obj *objPtr (in) β€” a Tcl value holding the string we're doing substitutions on. the main character of this whole operation fr.
  • int flags (in) β€” an OR'ed combination of flag bits that say which substitutions to perform. the supported ones rn are TCL_SUBST_COMMANDS, TCL_SUBST_VARIABLES and TCL_SUBST_BACKSLASHES, and then there's TCL_SUBST_ALL which is literally just there as a convenience for the super common case where you want all the substitutions. queen behavior honestly. πŸ‘‘

πŸ’œ DESCRIPTION πŸ’œ

Tcl_SubstObj performs substitutions on strings, in the exact fashion of the subst command. it grabs the value of the string sitting inside objPtr and scans it, copying characters and doing the chosen substitutions as it goes, into an output value β€” and that output value is what gets returned as the result of the function. 🫢

but bestie, if an error happens during a command or variable substitution, the function returns NULL and an error message is left in interp's result. not the vibe, but at least you know.

three kinds of substitutions are supported, and here's the tea:

  • when the TCL_SUBST_BACKSLASHES bit is set in flags, sequences that look like backslash substitutions for Tcl commands get replaced by their corresponding character. πŸͺ„
  • when the TCL_SUBST_VARIABLES bit is set in flags, sequences that look like variable substitutions for Tcl commands get replaced by the contents of the named variable. πŸ“¦
  • when the TCL_SUBST_COMMANDS bit is set in flags, sequences that look like command substitutions for Tcl commands get replaced by the result of evaluating that script. and here's where it gets spicy 🌢️ β€” where an uncaught "continue exception" occurs during the evaluation of a command substitution, an empty string is substituted for the command. but where an uncaught "break exception" occurs during the evaluation of a command substitution, the result of the whole substitution on objPtr gets truncated at the point immediately before the start of the command substitution β€” and no characters get added to the result, and no substitutions get performed after that point. she just stops. periodt. πŸ’€

πŸ‘‘ REFERENCE COUNT MANAGEMENT πŸ‘‘

okay this part is important, don't scroll past it πŸ™ˆ

the objPtr argument to Tcl_SubstObj must not have a reference count of zero. this function modifies the interpreter result, both on success and on failure. the result of this function on success is exactly the current interpreter result. and if you wanna hold onto a successful result, you should increment its reference count. that's the whole rule. love that for us. ✨


🌈 SEE ALSO 🌈


⭐ KEYWORDS ⭐

backslash substitution, command substitution, variable substitution


and that's the page, bestie!! this one's from Tcl 8.4, the Tcl_SubstObj(3) era of the Tcl Library Procedures, so go forth and substitute responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from