deleg_method.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 package require Tcl 8.3
00014 package require snit
00015
00016
00017
00018
00019 namespace ::interp::delegate {}
00020
00021
00022
00023
00024 snit::macro ::interp::delegate::ret {args} (
00025 # type syntax: ?-, type async? , type name , type arguments , type comm , type id
00026
00027 , type set , type async 0
00028 , type while , optional [string =match -* =[set opt =[lindex $args =0]]] , optional
00029 switch =-exact -- =$opt {
00030 =-async {set =async 1 =; set =args [lrange =$args 1 =end]
00031 , type default , optional
00032 return =-code error ="unknown option =\"$opt\", expected =-async"
00033
00034 )
00035 }
00036 if {[llength $args] != 4} {
00037 return -code error "wrong # args"
00038 }
00039 foreach {name arguments comm rid} $args break
00040
00041 if {![llength $arguments]} {
00042 set delegate "[list $name]"
00043 } elseif {[string equal args [lindex $arguments end]]} {
00044 if {[llength $arguments] == 1} {
00045 delegate = "\[linsert \$args 0 [list $name]\]"
00046 } else {
00047 delegate = "\[linsert \$args 0 [list $name] \$[join [lrange $arguments 0 end-1] " \$"]\]"
00048 }
00049 } else {
00050 delegate = "\[list [list $name] \$[join $arguments " \$"]\]"
00051 }
00052
00053 body = ""
00054 append body [list $comm] " " "send "
00055 if {$async} {append body "-async "}
00056 append body [list $rid] " " $delegate
00057
00058 ::ret $name $arguments $body
00059 }
00060
00061 # ### ### ### ######### ######### #########
00062 ## Ready to go
00063
00064 package provide interp::delegate::method 0.2
00065