Luc <
[email protected]d> wrote:
On Wed, 13 Mar 2024 13:34:28 -0500, Gerald Lester wrote:
Almost anything is possible and just about anything is permitted. That >>does not mean you should do it.
Almost? What is not possible?
(As an ice breaker for starting - below it I'm more serious)
In the past, "making coffee" was a standard answer to that, but in
some EuroTcl conferences of last few years, we have learnt better,
so, I'll say "making hot chocolate", until John's devices fill that
gap ;-)
I have seen package if needed that read from database and others that >>pulled over a socket.
But have you seen any of that documented?
The relevant documentation is the doc for "package" and within
that the paragraph about "ifneeded".
from there, we will analyze the building blocks one by one...
package ifneeded fubar 1.42.54 {puts hello}
Essentially, with that command you tell the tcl interp that:
If ever you need version 1.42.54 of package fubar, then
execute this script: {puts hello}
If your script lateron calls this command:
package require fubar
then you'll see the "hello" printed out, and it will detect, that
calling this script didn't really do its job of "providing" the
package:
% package require fubar
hello
attempt to provide package fubar 1.42.54 failed: no version of package fubar provided
%
Now lets have another look at what BWidget does:
package ifneeded BWidget 1.9.16 "\
package require Tk 8.1.1;\
[list tclPkgSetup $dir BWidget 1.9.16 {
{arrow.tcl source {ArrowButton ::ArrowButton::create ::ArrowButton::use}}
{labelframe.tcl source {LabelFrame ::LabelFrame::create ::LabelFrame::use}}
{labelentry.tcl source {LabelEntry ::LabelEntry::create ::LabelEntry::use}}
Upon eventually requiring BWidget later, the following script would
be executed:
package require Tk 8.1.1
tclPkgSetup $dir BWidget 1.9.16 { ... }
where $dir is actually replaced already within BWidget's pkgIndex.tcl,
so commands are really something like:
package require Tk 8.1.1
tclPkgSetup /x/y/z BWidget 1.9.16 { ... }
What is inside the curlies is only relevant to that command "tclPkgSetup"
which expects a nested list structure describing files, types, and a
list of commands that will be made available by treating the file
according to its type.
tclPkgSetup is really a helper procedure, whose definition can be
examined using: info body tclPkgSetup
I didn't find any man-page for that helper command. Googling
for it might find something.
Eventually, the script have called something like
package provide BWidget 1.9.16
(which, btw., the "tclPkgSetup" does inside it, among other stuff)
So we could create our dummy package correctly like this:
package ifneeded fubar 1.42.54 { package provide fubar 1.42.54 }
and a later
package require fubar
will return "1.42.54" as the version successfully loaded.
Anything else that your package will later need to get loaded
ought to be prepared within that script.
- What does Tcl expect from a pkgIndex.tcl file?
That it sets up the "ifneeded" script, that will be executed once
the package is actually required by a specific application script.
- What is the absolute minimum information it must contain?
It could be empty, but then it would be useless.
It could contain a "puts hello", but that would be printed regardless
of whether the package is actually needed for a tcl application, so
would be very bad practise.
Ideally it would only contain "package ifneeded" invocations for each
package it is meant to make available.
package ifneeded moinmoin 0.0.1 {
puts "Good morning, Tcl!"
package provide moinmoin 0.0.1
}
- What is the correct format of the information?
A tcl script that does the "right thing"(tm) for the package at hand.
- What else is allowed?
As little as possible to get the package advertising done.
Anything else would make tcl startup slower for all scripts,
even those not needing that package.
- In what format?
in tcl script format. (That means, it could contain nested
blocks of utter garbage, as long as that garbage is corrctly
understood by the command to which the garbage is really passed.)
- What are the effects of such options?
That depends on the command, to which they are actually passed.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)