namespace upvar
Links local names to variables of a namespace.
namespace upvar NS OTHERVAR MYVAR ?OTHERVAR MYVAR ...?
Description
For each pair, makes the local name MYVAR a link to the variable OTHERVAR of the namespace NS, as upvar does for a caller. A read or a write of MYVAR reads or writes the variable of NS. The variable need not exist yet.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| NS | namespace name | required | The namespace of the variables. |
| OTHERVAR | variable name | required | A variable of NS. |
| MYVAR | variable name | required | The local name of the link. |
Returns
An empty string.
Examples
% namespace eval cb {variable n 3}
> proc pu {} {namespace upvar ::cb n local; incr local}
> pu
> set cb::n
4
Errors
% namespace upvar cb n
wrong # args: should be "namespace upvar ns ?otherVar myVar ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
- A NS that does not exist is not an error. Tcl 8.6 gives the error
namespace "NS" not found in "::".
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1