link(n)
π link(n) β TclOO Commands π
okay so bestie, welcome to the link(n) page from the TclOO Commands manual. This one is literally about making methods callable as commands inside your methods, no cap. Think less βraw object nameβ and more βshortcut era.β β¨
πΈ NAME πΈ
link β create a link from a command to a method of an object π«Ά
π SYNOPSIS π
package require tcl::oo
link methodName ?...?
link {commandName methodName} ?...?
π DESCRIPTION π
The link command is available inside methods. It takes a series of one or more method names (methodName ...) and/or pairs of command-name and method-name ({commandName methodName}), and it makes those named methods available as commands without making you spell out the object name or use the my command. Iconic. π
The method does not need to exist at the time the link is made, bestie. If link is invoked when the method does not exist, the standard unknown method handling system is used. No extra drama invented here. π
The command name under which the method becomes available defaults to the method name, except where it is explicitly specified through an alias/method pair. Formally, every argument must be a list: if the list has two elements, the first element is the name of the command to create and the second element is the name of the method of the current object to which the command links; otherwise, the name of the command and the name of the method are the same string (the first element of the list).
If the name of the command is not a fully-qualified command name, it will be resolved with respect to the current namespace (i.e., the object namespace). Slay. β¨
π¦ EXAMPLES π¦
This demonstrates linking a single method in various ways. First it makes a simple link, then a renamed link, then an external link. Note that the method itself is unexported, but it can still be called directly from outside the class. So yes, itβs giving sneaky-but-legal. π
oo::class create ABC {
method Foo {} {
puts "This is Foo in [self]"
}
constructor {} {
link Foo
# The method Foo is now directly accessible as Foo here
link {bar Foo}
# The method Foo is now directly accessible as bar
link {::ExternalCall Foo}
# The method Foo is now directly accessible in the global
# namespace as ExternalCall
}
method grill {} {
puts "Step 1:"
Foo
puts "Step 2:"
bar
}
}
ABC create abc
abc grill
β Step 1:
β This is Foo in ::abc
β Step 2:
β This is Foo in ::abc
# Direct access via the linked command
puts "Step 3:"; ExternalCall
β Step 3:
β This is Foo in ::abc
This example shows that multiple linked commands can be made in a call to link, and that they can handle arguments. Multi-link slay. π
oo::class create Ex {
constructor {} {
link a b c
# The methods a, b, and c (defined below) are all now
# directly accessible within methods under their own names.
}
method a {} {
puts "This is a"
}
method b {x} {
puts "This is b($x)"
}
method c {y z} {
puts "This is c($y,$z)"
}
method call {p q r} {
a
b $p
c $q $r
}
}
set o [Ex new]
$o call 3 5 7
β This is a
β This is b(3)
β This is c(5,7)
π SEE ALSO π
π KEYWORDS π
- command
- method
- object
okay thatβs the whole link(n) vibe, bestie. Signing off with the footer facts: this is from TclOO, version 0.3, and the footer doesnβt show a date β so no fake date energy from me, periodt. ππ
π¦ 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
- nixos 26.05: tcl 9.0.3
- Copyright (c) 2011-2015 Andreas Kupries
- Copyright (c) 2018 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms