Skip to content

uplevel

Execute a script in the context of a caller's stack frame.

Syntax

tcl
uplevel ?level? command ?arg ...?

Parameters

  • level: Stack level to execute in (default: 1). Can be:
    • A relative level N - moves N levels up the call stack
    • An absolute level #N - targets absolute stack frame number
  • command: The command to execute
  • arg: Additional arguments concatenated with command (joined with spaces)

Description

The uplevel command evaluates a script in a different stack frame context:

  1. Parses an optional level specifier (relative N or absolute #N)
  2. Defaults to level 1 (caller's frame) when level is omitted
  3. Concatenates multiple arguments with spaces to form the script
  4. Temporarily switches the active frame to the target level
  5. Evaluates the script in that frame's variable context
  6. Returns the result of the script evaluation

Supported Features

FeatureNotes
Relative level (N)Moves N levels up the call stack
Absolute level (#N)Targets absolute stack frame number
Default level of 1Used when level is omitted
Multiple argument concatenationArguments are joined with spaces
Variable context switchingScript executes with target frame's variables
Result propagationReturns result of evaluated script
Error propagationErrors from script evaluation are propagated
Namespace interactionNamespace eval and procs add call frames correctly
Apply command interactionApply adds call frames that count for uplevel

Examples

Output

See Also