Tcl_UpVar(3tcl)
π Tcl_UpVar β bestie, we're linking variables π
okay so welcome to the Tcl_UpVar page from the Tcl Library Procedures manual, section 3tcl. sit down, grab a boba, because we're about to make two variables share a whole soul. π«Ά
β¨ NAME β¨
Tcl_UpVar, Tcl_UpVar2 β link one variable to another
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_UpVar(interp, frameName, sourceName, destName, flags)
int
Tcl_UpVar2(interp, frameName, name1, name2, destName, flags)
π ARGUMENTS π
Tcl_Interp *interp(in) β the interpreter that's holding all these variables; it's also the one that gets to spill the tea when something goes wrong (error reporting, bestie).const char *frameName(in) β tells us which stack frame the source variable is chilling in. it can take any of the forms theupvarcommand accepts, like#0or1. slay.const char *sourceName(in) β the name of the source variable, living in the frame given byframeName. it can point at a plain scalar variable, or at an array variable with a parenthesized index. either way, we see you. πconst char *destName(in) β the name of the destination variable, which is gonna get linked to the source variable so that literally every reference todestNamesecretly refers to the other one. it must not already exist, unless it exists as an upvar-ed variable. no squatters, periodt.int flags(in) β one ofTCL_GLOBAL_ONLY,TCL_NAMESPACE_ONLYor0. if it's non-zero, thendestNameis a global or namespace variable; otherwise it's local to the current procedure (or local to the current namespace if there's no procedure active). choose your fighter. πconst char *name1(in) β the first part of the source variable's name (the scalar name, or the name of the array without the array index).const char *name2(in) β if the source variable is an element of an array, this gives the index of that element. for scalar source variables, it'sNULL. icon behavior.
π DESCRIPTION π
Tcl_UpVar and Tcl_UpVar2 do exactly what the upvar command does: they make a link from a source variable to a destination variable, so that references to the destination get passed transparently through to the source. it's giving "you are me and I am you" energy. π¦
the name of the source variable can be specified two ways:
- as a single string, like
xyxora(24)β that's when you callTcl_UpVar - in two parts, where the array name has been separated from the element name β that's when you call
Tcl_UpVar2
the destination variable name is always specified as a single string, and no, it may not be an array element. not up for debate. π
both procedures return either TCL_OK or TCL_ERROR, and if an error happens they leave an error message in the interpreter's result. so check that result, bestie, don't just assume.
as with the upvar command, the source variable doesn't even need to exist yet β she can be a total mystery. and if she does exist, unsetting it later does not destroy the link. the link is forever, no cap. π₯
the destination variable may exist at the time of the call, but if it does, it has to exist as a linked variable. that's the vibe check and it is non-negotiable.
π KEYWORDS π
linked variable, upvar, variable
and that's the whole page, bestie!! π this one's from the <strong>Tcl 7.4</strong> era, filed under <strong>Tcl_UpVar(3tcl)</strong> in the Tcl Library Procedures manual β like, old-school iconic but still hitting. go forth and link those variables. mwah. πβ¨π«Ά
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms