Group: comp.lang.tcl


Subject: pkgIndex.tcl oddity
From: Eric
Date: 11/7/2007 1:48:43 PM
I have pkgIndex.tcl : package ifneeded mypkg 0.1 \ [list source [file join $dir mypkg.tcl]] and mypkg.tcl : package provide mypkg 0.1 puts $dir I get an error when mypkg.tcl is sourced during "package require" because variable dir does not exist. But if I change pkgIndex.tcl to : package ifneeded mypkg 0.1 \ [list set dir $dir ; source [file join $dir mypkg.tcl]] then everything is OK. So the simple question is, why is dir not available in the first case? Now for the weird bit. If I have pkgIndex.tcl : package ifneeded mypkg 0.1 \ [list set xdir $dir ; source [file join $dir mypkg.tcl]] and mypkg.tcl : package provide mypkg 0.1 puts $xdir then the error comes back because xdir does not exist. I do not understand this at all. TIA Eric

Subject: pkgIndex.tcl oddity
From: Glenn Jackman
Date: 11/7/2007 3:56:17 PM
At 2007-11-07 08:48AM, "Eric" wrote: > I have pkgIndex.tcl : > > package ifneeded mypkg 0.1 \ > [list source [file join $dir mypkg.tcl]] > > and mypkg.tcl : > > package provide mypkg 0.1 > puts $dir > > I get an error when mypkg.tcl is sourced during "package require" > because variable dir does not exist. But if I change pkgIndex.tcl to : I think that dir variable is local to some code in the auto-load mechanism. The "source ..." argument of the [package ifneeded] command would be [eval]'ed somewhere $dir is defined. It certainly is not a global variable for you to use in your script. If you need to know the directory where your package was found, you may have to iterate through subdirectories of the directories in the $auto_path variable. I don't think there's a command that answers "in which directory is package foobar?" -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry

Subject: pkgIndex.tcl oddity
From: Glenn Jackman
Date: 11/7/2007 5:25:55 PM
At 2007-11-07 11:06AM, "Gerald W. Lester" wrote: > Glenn Jackman wrote: > > If you need to know the directory where your package was found, you may > > have to iterate through subdirectories of the directories in the > > $auto_path variable. I don't think there's a command that answers "in > > which directory is package foobar?" > > Try: [file dirname [info script]] You have to build that info your package. What if I want to know where, say, the script file for the fileutil package lives? I'm not going to modify all the packages I get from ActiveTcl. It would be nice if there was an equivalent to [info loaded] for sourced package files. -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry

Subject: pkgIndex.tcl oddity
From: Glenn Jackman
Date: 11/8/2007 2:24:31 PM
At 2007-11-07 04:08PM, "Michael Schlenker" wrote: > Glenn Jackman schrieb: > > It would be nice if there was an equivalent to [info loaded] for sourced > > package files. > > You can get that info with the new TIP280 feature [info frame]. > http://www.tcl.tk/cgi-bin/tct/tip/280.html I don't think you can. I'm referring to: % info loaded {{} Tk} {{C:/Program Files/Tcl/lib/tcl8.4/reg1.1/tclreg11.dll} Registry} % load {C:/Program Files/Tcl/lib/snack2.2/libsnack.dll} Snack % info loaded {{C:/Program Files/Tcl/lib/snack2.2/libsnack.dll} Snack} {{} Tk} {{C:/Program Files/Tcl/lib/tcl8.4/reg1.1/tclreg11.dll} Registry} Where the interpreter remembers what files have been [load]ed. After reading that TIP, I don't think you can say: package require mypackage some_cmd_to_return_list_of_sourced_files_and_optional_package_name -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry