Skip to content

upvar

Create references to variables in other stack frames.

Syntax

tcl
upvar ?level? otherVar localVar ?otherVar localVar ...?

Parameters

  • level: Stack level (default: 1). Use integer for relative levels or #n for absolute
  • otherVar: Variable name in the target frame
  • localVar: Local name to create as an alias

Description

Creates local variables that are aliases to variables in another stack frame. Level 1 refers to the caller's frame, 2 to the caller's caller, and so on. Level #0 refers to the global scope. Changes to the local alias affect the original variable.

Examples

Pass by reference

Output

Swap two variables

Output

Accessing global scope with #0

Output

Building data structures

Output

See Also

  • global - Access global variables
  • variable - Declare namespace variables
  • uplevel - Execute script in another frame