deleg_proc.tcl

Go to the documentation of this file.
00001 /*  interp.tcl*/
00002 /*  Some utility commands for creation of delegation procedures*/
00003 /*  (Delegation of commands to a remote interpreter via a comm*/
00004 /*  handle).*/
00005 /* */
00006 /*  Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>*/
00007 /* */
00008 /*  See the file "license.terms" for information on usage and redistribution*/
00009 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00010 /*  */
00011 /*  RCS: @(#) $Id: deleg_proc.tcl,v 1.2 2006/09/01 19:58:21 andreas_kupries Exp $*/
00012 
00013 package require Tcl 8.3
00014 
00015 /*  ### ### ### ######### ######### #########*/
00016 /*  Requisites*/
00017 
00018 namespace ::interp::delegate {}
00019 
00020 /*  ### ### ### ######### ######### #########*/
00021 /*  Public API*/
00022 
00023 ret  ::interp::delegate::proc (type args) {
00024     # syntax: ?-async? name arguments comm id
00025 
00026     set async 0
00027     while {[string match -* [set opt [lindex $args 0]]]} {
00028     switch -exact -- $opt {
00029         -async {
00030         set async 1
00031         set args [lrange $args 1 end]
00032         }
00033         default {
00034         return -code error "unknown option \"$opt\", expected -async"
00035         }
00036     }
00037     }
00038     if {[llength $args] != 4} {
00039     return -code error "wrong # args"
00040     }
00041     foreach {name arguments comm rid} $args break
00042     set base [namespace tail $name]
00043 
00044     if {![llength $arguments]} {
00045     set delegate "[list $base]"
00046     } elseif {[string equal args [lindex $arguments end]]} {
00047     if {[llength $arguments] == 1} {
00048         set delegate "\[linsert \$args 0 [list $base]\]"
00049     } else {
00050         set delegate "\[linsert \$args 0 [list $base] \$[join [lrange $arguments 0 end-1] " \$"]\]"
00051     }
00052     } else {
00053     set delegate "\[list [list $base] \$[join $arguments " \$"]\]"
00054     }
00055 
00056     set    body ""
00057     append body [list $comm] " " "send "
00058     if {$async} {append body "-async "}
00059     append body [list $rid] " " $delegate
00060 
00061     uplevel 1 [list ::proc $name $arguments $body]
00062     return $name
00063 }
00064 
00065 /*  ### ### ### ######### ######### #########*/
00066 /*  Ready to go*/
00067 
00068 package provide interp::delegate::ret  0.2
00069 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1