Tcl_UpVar(3)
π¦ Tcl_UpVar β link one variable to another π¦
okay bestie, sit down, hydrate, because this is the Tcl library page for Tcl_UpVar and Tcl_UpVar2 (that's the Tcl_UpVar(3) manual, she's iconic, she's from the Tcl Library Procedures, mwah π
) and she's literally about making two variables hold hands forever.
β¨ 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 your variables; also the one that's gonna spill the tea if something goes wrong, because it's used for error reporting.const char *frameName(in) β this is how we find the stack frame that's holding the source variable. she accepts literally any of the forms that theupvarcommand accepts, like#0or1. yes ma'am, all of them. πconst char *sourceName(in) β the name of the source variable, living inside the frame thatframeNamepicked out. this can be a plain scalar variable, OR an array variable with a parenthesized index. so like, both vibes are valid. β¨const char *destName(in) β the name of the destination variable, aka the one that gets linked to the source so that anything you say aboutdestNameis secretly about the other variable. π big "we're the same person actually" energy.
π¨ bestie listen: destName must not currently exist, unless it exists as an upvar-ed variable. no random pre-existing variable, that's not the move.
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, if no procedure is active, local to the current namespace). pick your fighter. πconst char *name1(in) β the first part of the source variable's name. that's 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 is the index of that element. for scalar source variables? it'sNULL. that's it, that's the whole job. π
π DESCRIPTION π
Tcl_UpVar and Tcl_UpVar2 do exactly what the upvar command does β same functionality, no cap. 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're my proxy now, bestie". π₯
you can name the source variable two ways:
- as a single string, like
xyxora(24)β that's what you do when you callTcl_UpVar. - in two parts, where the array name has been separated from the element name β that's what you do when you call
Tcl_UpVar2.
the destination variable name gets given as a single string. and nope, it may not be an array element. periodt. π
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, okay? π
and just like with the upvar command, the source variable doesn't even have to exist. iconic behaviour honestly. if it does exist, unsetting it later does not destroy the link β the link survives, she's resilient. π§
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 rule, we don't make them. β
π KEYWORDS π
linked variable, upvar, variable π
okay that's the whole page, you ate it, I'm so proud of you π this was Tcl_UpVar(3) from the Tcl manual, version 7.4, dated 7.4 β and that's the cute little sign-off from your fave manpage bestie. go forth and link some variables, mwah πβ¨π¦
π¦ 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) 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