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

### 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

callback, mymethod — 手段への呼戻しを創生する Generate callbacks to methods

### 構文 SYNOPSIS

package require tcl::oo
callback methodName ?arg ...?
mymethod methodName ?arg ...?

### 説明 DESCRIPTION

callback 命令は､ Tcllib の ooutil と snit 梱包では互換性の為に mymethod と呼ばれ､又､それは手段への呼出しの文脈の内部からのみ使われるべきもので､実行される時､現在の対象上の手段( self の報告に従い)､ methodName を起動することになる記述譜断片の創生に使用される｡提供された､どの追加の引数も､呼戻しへの最初の引数として提供されることになる｡結果の記述譜断片は適切なリストである｡ The callback command, also called mymethod for compatibility with the ooutil and snit packages of Tcllib, and which should only be used from within the context of a call to a method (i.e. inside a method, constructor or destructor body) is used to generate a script fragment that will invoke the method, methodName, on the current object (as reported by self) when executed. Any additional arguments provided will be provided as leading arguments to the callback. The resulting script fragment shall be a proper list.

註意すべきは､現在の対象が methodName の呼出しを扱えることを確認することは呼出者の責務である; この命令はそれを確認しない｡methodName はどれであれ､移送された手段や移送されない手段を参照するかもしれないが､私的手段は参照しない､後者は唯一､手段内部から直接に起動され得るのみである｡もしその位置にその様な手段がない場合､呼戻しが起動された時に､標準の unknown の手段操作子が呼出されることになる｡ Note that it is up to the caller to ensure that the current object is able to handle the call of methodName; this command does not check that. methodName may refer to any exported or unexported method, but may not refer to a private method as those can only be invoked directly from within methods. If there is no such method present at the point when the callback is invoked, the standard unknown method handler will be called.

### 用例 EXAMPLE

これは単純な復唱の業務譜級である｡callback 命令は二つの場所で使われ､ Accept 手段によって取扱われる入力受け口接続の為に準備し､又､これらの接続で Receive 手段によって扱われる入力バイトの為の準備する｡ This is a simple echo server class. The callback command is used in two places, to arrange for the incoming socket connections to be handled by the Accept method, and to arrange for the incoming bytes on those connections to be handled by the Receive method.

    oo::class create EchoServer {
        variable server clients
        constructor {port} {
            set server [socket -server [callback Accept] $port]
            set clients {}
        }
        destructor {
            chan close $server
            foreach client [dict keys $clients] {
                chan close $client
            }
        }

        method Accept {channel clientAddress clientPort} {
            dict set clients $channel [dict create \
                    address $clientAddress port $clientPort]
            chan event $channel readable [callback Receive $channel]
        }
        method Receive {channel} {
            if {[chan gets $channel line] >= 0} {
                my echo $channel $line
            } else {
                chan close $channel
                dict unset clients $channel
            }
        }

        method echo {channel line} {
            dict with clients $channel {
                chan puts $channel \
                        [format {[%s:%d] %s} $address $port $line]
            }
        }
    }

### SEE ALSO

chan, fileevent, my, self, socket, trace

### KEYWORDS

callback, object
Copyright © 2018 Donal K. Fellows