1
votes

I am working with some legacy TCL scripts that use auto_mkindex. To understand how it works, I have set up a minimal example but have not been able to correctly source the files. My starting files are

.
├── main.tcl
└── util
    └── hello.tcl

The file contents are:

# main.tcl
puts [hello]

# hello.tcl
proc hello {} {
    return "Hello World"
}

In ./util I ran auto_mkindex . from tclsh which generated a tclIndex file in ./util with the line

set auto_index(hello) [list source [file join $dir hello.tcl]]

Then when using tclsh from the root of the project I append auto_path with the path to the util directory. However, when I call hello I get an error saying Invalid command name "hello". Clearly I'm missing something. What is it?

1
I think we need more detail about your current directory, and the command used to manipulate auto_path. This works for me: env TCLLIBPATH="$TCLLIBPATH ./util" tclsh main.tclglenn jackman
@glennjackman thanks for pointing me in the right direction. It was as simple as having the wrong path appended to auto_path.mentoc3000

1 Answers

0
votes

For a tclIndex file to work, it must be in a directory on the auto_path.

Check with:

foreach dir $auto_path {
    puts "$dir -> [glob -nocomplain -directory $dir tclIndex]"
}

It's very easy to put the wrong path on. However, it's often easiest to make your main script add paths relative to itself:

lappend auto_path [file join [file dirname [file normalize [info script]]]] util]