Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a question about package in TCL

Tags:

package

tcl

I have a question about package in TCL

I have a test1.tcl file:

package provide hello 0.1.0


set globalVariable 20

this file in required in test2.tcl

package require hello 0.1.0

puts $globalVariable

and the pkgIndex.tcl is:

package ifneeded hello 0.1.0 [list source [file join $dir test1.tcl]]

when I execute the test2.tcl, it tells me, the package hello 0.1.0 is not found.

I try to execute the pkgIndex.tcl, it tells me can not read variable dir, all of these three files are under the same folder. how could I fix it? can anyone help?


1 Answers

You need to read the documentation for pkg_mkIndex which explains how the interpreter goes about looking for packages to load. The short version is:

Install the package as a subdirectory of one of the directories given by the tcl_pkgPath variable. If you install the package anywhere else, then you must ensure that the directory containing the package is in the auto_path global variable or an immediate subdirectory of one of the directories in auto_path.

like image 57
Jackson Avatar answered Dec 08 '25 20:12

Jackson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!