Tcl_SubstObj(3)
π 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 areTCL_SUBST_COMMANDS,TCL_SUBST_VARIABLESandTCL_SUBST_BACKSLASHES, and then there'sTCL_SUBST_ALLwhich 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_BACKSLASHESbit is set inflags, sequences that look like backslash substitutions for Tcl commands get replaced by their corresponding character. πͺ - when the
TCL_SUBST_VARIABLESbit is set inflags, sequences that look like variable substitutions for Tcl commands get replaced by the contents of the named variable. π¦ - when the
TCL_SUBST_COMMANDSbit is set inflags, 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 onobjPtrgets 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
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 2001 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms