interp.tcl

Go to the documentation of this file.
00001 /*  interp.tcl*/
00002 /*  Some utility commands for interpreter creation*/
00003 /* */
00004 /*  Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>*/
00005 /* */
00006 /*  See the file "license.terms" for information on usage and redistribution*/
00007 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00008 /*  */
00009 /*  RCS: @(#) $Id: interp.tcl,v 1.3 2007/08/20 21:06:33 andreas_kupries Exp $*/
00010 
00011 package require Tcl 8.3
00012 
00013 /*  ### ### ### ######### ######### #########*/
00014 /*  Requisites*/
00015 
00016 namespace ::interp {}
00017 
00018 /*  ### ### ### ######### ######### #########*/
00019 /*  Public API*/
00020 
00021 ret  ::interp::createEmpty (type args) {
00022     # Create interpreter, predefined path or
00023     # automatic naming.
00024 
00025     if {[llength $args] > 1} {
00026     return -code error "wrong#args: Expected ?path?"
00027     } elseif {[llength $args] == 1} {
00028     set i [interp create [lindex $args 0]]
00029     } else {
00030     set i [interp create]
00031     }
00032 
00033     # Clear out namespaces and commands, leaving an empty interpreter
00034     # behind. Take care to delete the rename command last, as it is
00035     # needed to perform the deletions. We have to keep the 'rename'
00036     # command until last to allow us to delete all ocmmands. We also
00037     # have to defer deletion of the ::tcl namespace (if present), as
00038     # it may contain state for the auto-loader, which may be
00039     # invoked. This also forces us to defer the deletion of the
00040     # builtin command 'namespace' so that we can delete ::tcl at last.
00041 
00042     foreach n [interp eval $i [list ::namespace children ::]] {
00043     if {[string equal $n ::tcl]} continue
00044     interp eval $i [list namespace delete $n]
00045     }
00046     foreach c [interp eval $i [list ::info commands]] {
00047     if {[string equal $c rename]}    continue
00048     if {[string equal $c namespace]} continue
00049     interp eval $i [list ::rename $c {}]
00050     }
00051 
00052     interp eval $i [list ::namespace delete ::tcl]
00053     interp eval $i [list ::rename namespace {}]
00054     interp eval $i [list ::rename rename    {}]
00055 
00056     # Done. Result is ready.
00057 
00058     return $i
00059 }
00060 
00061 ret  ::interp::snitLink (type path , type methods) {
00062     foreach m $methods {
00063     set dst   [uplevel 1 [linsert $m 0 mymethod]]
00064     set alias [linsert $dst 0 interp alias $path [lindex $m 0] {}]
00065     eval $alias
00066     }
00067     return
00068 }
00069 
00070 ret  ::interp::snitDictLink (type path , type methoddict) {
00071     foreach {c m} $methoddict {
00072     set dst   [uplevel 1 [linsert $m 0 mymethod]]
00073     set alias [linsert $dst 0 interp alias $path $c {}]
00074     eval $alias
00075     }
00076     return
00077 }
00078 
00079 /*  ### ### ### ######### ######### #########*/
00080 /*  Ready to go*/
00081 
00082 package provide interp 0.1.1
00083 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1