📄 pkgmkindex.n
字号:
'\"'\" Copyright (c) 1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) pkgMkIndex.n 1.8 97/10/31 12:51:13'\" .so man.macros.TH pkg_mkIndex n 7.6 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEpkg_mkIndex \- Build an index for automatic loading of packages.SH SYNOPSIS.nf\fBpkg_mkIndex \fIdir\fR \fIpattern \fR?\fIpattern pattern ...\fR?.fi.BE.SH DESCRIPTION.PP\fBPkg_mkIndex\fR is a utility procedure that is part of the standardTcl library.It is used to create index files that allow packages to be loadedautomatically when \fBpackage require\fR commands are executed.To use \fBpkg_mkIndex\fR, follow these steps:.IP [1]Create the package(s).Each package may consist of one or more Tcl script files or binary files.Binary files must be suitable for loading with the \fBload\fR commandwith a single argument; for example, if the file is \fBtest.so\fR it mustbe possible to load this file with the command \fBload test.so\fR.Each script file must contain a \fBpackage provide\fR command to declarethe package and version number, and each binary file must containa call to \fBTcl_PkgProvide\fR..IP [2]Create the index by invoking \fBpkg_mkIndex\fR.The \fIdir\fR argument gives the name of a directory and each\fIpattern\fR argument is a \fBglob\fR-style pattern that selectsscript or binary files in \fIdir\fR.\fBPkg_mkIndex\fR will create a file \fBpkgIndex.tcl\fR in \fIdir\fRwith package information about all the files given by the \fIpattern\fRarguments.It does this by loading each file and seeing what packagesand new commands appear (this is why it is essential to have\fBpackage provide\fR commands or \fBTcl_PkgProvide\fR callsin the files, as described above)..VS "" br.IP [3]Install the package as a subdirectory of one of the directories given bythe \fBtcl_pkgPath\fR variable. If \fB$tcl_pkgPath\fR contains morethan one directory, machine-dependent packages (e.g., those thatcontain binary shared libraries) should normally be installedunder the first directory and machine-independent packages (e.g.,those that contain only Tcl scripts) should be installed under thesecond directory.The subdirectory should includethe package's script and/or binary files as well as the \fBpkgIndex.tcl\fRfile. As long as the package is installed as a subdirectory of adirectory in \fB$tcl_pkgPath\fR it will automatically be found during\fBpackage require\fR commands..RS.LPIf you install the package anywhere else, then you must ensure thatthe directory contaiingn the package is in the \fBauto_path\fR global variableor an immediate subdirectory of one of the directories in \fBauto_path\fR.\fBAuto_path\fR contains a list of directories that are searchedby both the auto-loader and the package loader; by default itincludes \fB$tcl_pkgPath\fR.The package loader also checks all of the subdirectories of thedirectories in \fBauto_path\fR..VEYou can add a directory to \fBauto_path\fR explicitly in yourapplication, or you can add the directory to your \fBTCLLIBPATH\fRenvironment variable: if this environment variable is present,Tcl initializes \fBauto_path\fR from it during application startup..RE.IP [4]Once the above steps have been taken, all you need to do to use apackage is to invoke \fBpackage require\fR.For example, if versions 2.1, 2.3, and 3.1 of package \fBTest\fRhave been indexed by \fBpkg_mkIndex\fR, the command\fBpackage require Test\fR will make version 3.1 availableand the command \fBpackage require \-exact Test 2.1\fR willmake version 2.1 available.There may be many versions of a package in the various index filesin \fBauto_path\fR, but only one will actually be loaded in a giveninterpreter, based on the first call to \fBpackage require\fR.Different versions of a package may be loaded in differentinterpreters..SH "PACKAGES AND THE AUTO-LOADER".PPThe package management facilities overlap somewhat with the auto-loader,in that both arrange for files to be loaded on-demand.However, package management is a higher-level mechanism that usesthe auto-loader for the last step in the loading process.It is generally better to index a package with \fBpkg_mkIndex\fRrather than \fBauto_mkindex\fR because the package mechanism providesversion control: several versions of a package can be made availablein the index files, with different applications using differentversions based on \fBpackage require\fR commands.In contrast, \fBauto_mkindex\fR does not understand versions soit can only handle a single version of each package. It is probably not a good idea to index a given package with both\fBpkg_mkIndex\fR and \fBauto_mkindex\fR.If you use \fBpkg_mkIndex\fR to index a package, its commands cannotbe invoked until \fBpackage require\fR has been used to select aversion; in contrast, packages indexed with \fBauto_mkindex\fRcan be used immediately since there is no version control..SH "HOW IT WORKS".PP\fBPkg_mkIndex\fR depends on the \fBpackage unknown\fR command,the \fBpackage ifneeded\fR command, and the auto-loader.The first time a \fBpackage require\fR command is invoked,the \fBpackage unknown\fR script is invoked.This is set by Tcl initialization to a script thatevaluates all of the \fBpkgIndex.tcl\fR files in the\fBauto_path\fR.The \fBpkgIndex.tcl\fR files contain \fBpackage ifneeded\fRcommands for each version of each available package; these commandsinvoke \fBpackage provide\fR commands to announce theavailability of the package, and they setup auto-loaderinformation to load the files of the package.A given file of a given version of a given package isn'tactually loaded until the first time one of its commandsis invoked.Thus, after invoking \fBpackage require\fR you won't seethe package's commands in the interpreter, but you will be ableto invoke the commands and they will be auto-loaded..SH KEYWORDSauto-load, index, package, version
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -