## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > link

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

link — 命令から対象の手段への連結を創生する Create link from command to method of object

### 構文 SYNOPSIS

package require tcl::oo
link methodName ?...?
link {commandName methodName} ?...?

### 説明 DESCRIPTION

link 命令は､手段の内部で利用できる｡それは一つ或はそれ以上の手段の名前の並び (methodName ...)､ 及び/又は 命令- と 手段-名 の対 ({commandName methodName})を採り､対象の名前や my 命令の明示的な使用を要求されずに命令として利用可能な､名前の付いた手段にする｡手段は連結が作られる時に実在する必要はない; もし手段が実在しない時に link 命令が起動されると標準的 unknown 手段処理体系が使われる｡ The link command is available within methods. It takes a series of one or more method names (methodName ...) and/or pairs of command- and method-name ({commandName methodName}) and makes the named methods available as commands without requiring the explicit use of the name of the object or the my command. The method does not need to exist at the time that the link is made; if the link command is invoked when the method does not exist, the standard unknown method handling system is used.

その元で手段が利用できる命令の名前は､無為設定では､手段の名前になる､但し明示的に 連結/手段 対を通して指定されたものを除く｡公式に､全ての引数はリストでなければならない; もしリストが二つの要素を有する場合､最初の要素は創生すべき命令の名前で､第二の要素はそこに命令が連結する現在の対象の手段の名前である; それ以外の場合､命令の名前と手段の名前は同じ文字列である(リストの最初の要素)｡ The command name under which the method becomes available defaults to the method name, except where 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).

### 用例 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 that it can still be called directly from outside the class.

    oo::class create ABC {
        method Foo {} {
            puts "This is Foo in [self]"
        }

        constructor {} {
            link Foo
            # 手段 foo は今や､ここで foo として直接利用できる
            # The method Foo is now directly accessible as Foo here
            link {bar Foo}
            # 手段 foo は今や､ bar として直接利用できる
            # The method Foo is now directly accessible as bar
            link {::ExternalCall Foo}
            # 手段 foo は今や､大域名前空間内でExternalCall として直接利用できる
            # 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.

    oo::class create Ex {
        constructor {} {
            link a b c
            # 手段 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

interp, my, oo::class, oo::define

### KEYWORDS

command, method, object
Copyright © 2011-2015 Andreas Kupries
Copyright © 2018 Donal K. Fellows