📄 package.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: @(#) package.n 1.5 96/03/18 14:17:31'\" .so man.macros.TH package n 7.5 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEpackage \- Facilities for package loading and version control.SH SYNOPSIS.nf\fBpackage forget \fIpackage\fR\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR?\fBpackage names\fR\fBpackage provide \fIpackage \fR?\fIversion\fR?\fBpackage require \fR?\fB\-exact\fR? \fIpackage \fR?\fIversion\fR?\fBpackage unknown \fR?\fIcommand\fR?\fBpackage vcompare \fIversion1 version2\fR\fBpackage versions \fIpackage\fR\fBpackage vsatisfies \fIversion1 version2\fR.fi.BE.SH DESCRIPTION.PPThis command keeps a simple database of the packages available foruse by the current interpreter and how to load them into theinterpreter.It supports multiple versions of each package and arrangesfor the correct version of a package to be loaded based on whatis needed by the application.This command also detects and reports version clashes.Typically, only the \fBpackage require\fR and \fBpackage provide\fRcommands are invoked in normal Tcl scripts; the other commands are usedprimarily by system scripts that maintain the package database..PPThe behavior of the \fBpackage\fR command is determined by its first argument.The following forms are permitted:.TP\fBpackage forget \fIpackage\fRRemoves all information about \fIpackage\fR from this interpreter,including information provided by both \fBpackage ifneeded\fR and\fBpackage provide\fR..TP\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR?This command typically appears only in system configurationscripts to set up the package database.It indicates that a particular version ofa particular package is available if needed, and that the packagecan be added to the interpreter by executing \fIscript\fR.The script is saved in a database for use by subsequent\fBpackage require\fR commands; typically, \fIscript\fRsets up auto-loading for the commands in the package (or calls\fBload\fR and/or \fBsource\fR directly), then invokes\fBpackage provide\fR to indicate that the package is present.There may be information in the database for several differentversions of a single package.If the database already contains information for \fIpackage\fRand \fIversion\fR, the new \fIscript\fR replaces the existingone.If the \fIscript\fR argument is omitted, the current script forversion \fIversion\fR of package \fIpackage\fR is returned,or an empty string if no \fBpackage ifneeded\fR command hasbeen invoked for this \fIpackage\fR and \fIversion\fR..TP\fBpackage names\fRReturns a list of the names of all packages in theinterpreter for which a version has been provided (via\fBpackage provide\fR) or for which a \fBpackage ifneeded\fRscript is available.The order of elements in the list is arbitrary..TP\fBpackage provide \fIpackage \fR?\fIversion\fR?This command is invoked to indicate that version \fIversion\fRof package \fIpackage\fR is now present in the interpreter.It is typically invoked once as part of an \fBifneeded\fR script,and again by the package itself when it is finally loaded.An error occurs if a different version of \fIpackage\fR has beenprovided by a previous \fBpackage provide\fR command.If the \fIversion\fR argument is omitted, then the commandreturns the version number that is currently provided, or anempty string if no \fBpackage provide\fR command has beeninvoked for \fIpackage\fR in this interpreter..TP\fBpackage require \fR?\fB\-exact\fR? \fIpackage \fR?\fIversion\fR?This command is typically invoked by Tcl code that wishes to usea particular version of a particular package. The argumentsindicate which package is wanted, and the command ensures thata suitable version of the package is loaded into the interpreter.If the command succeeds, it returns the version number that isloaded; otherwise it generates an error.If both the \fB\-exact\fRswitch and the \fIversion\fR argument are specified then only thegiven version is acceptable. If \fB\-exact\fR is omitted but\fIversion\fR is specified, then versions later than \fIversion\fRare also acceptable as long as they have the same major versionnumber as \fIversion\fR.If both \fB\-exact\fR and \fIversion\fR are omitted then anyversion whatsoever is acceptable.If a version of \fIpackage\fR has already been provided (by invokingthe \fBpackage provide\fR command), then its version number mustsatisfy the criteria given by \fB\-exact\fR and \fIversion\fR andthe command returns immediately.Otherwise, the command searches the database of information provided byprevious \fBpackage ifneeded\fR commands to see if an acceptableversion of the package is available.If so, the script for the highest acceptable version number is invoked;it must do whatever is necessary to load the package,including calling \fBpackage provide\fR for the package.If the \fBpackage ifneeded\fR database does not contain an acceptableversion of the package and a \fBpackage unknown\fR command has beenspecified for the interpreter then that command is invoked; whenit completes, Tcl checks again to see if the package is now providedor if there is a \fBpackage ifneeded\fR script for it.If all of these steps fail to provide an acceptable version of thepackage, then the command returns an error..TP\fBpackage unknown \fR?\fIcommand\fR?This command supplies a ``last resort'' command to invoke during\fBpackage require\fR if no suitable version of a package can be foundin the \fBpackage ifneeded\fR database.If the \fIcommand\fR argument is supplied, it contains the first partof a command; when the command is invoked during a \fBpackage require\fRcommand, Tcl appends two additional arguments giving the desired packagename and version.For example, if \fIcommand\fR is \fBfoo bar\fR and later the command\fBpackage require test 2.4\fR is invoked, then Tcl will executethe command \fBfoo bar test 2.4\fR to load the package.If no version number is supplied to the \fBpackage require\fR command,then the version argument for the invoked command will be an empty string.If the \fBpackage unknown\fR command is invoked without a \fIcommand\fRargument, then the current \fBpackage unknown\fR script is returned,or an empty string if there is none.If \fIcommand\fR is specified as an empty string, then the current\fBpackage unknown\fR script is removed, if there is one..TP\fBpackage vcompare \fIversion1 version2\fRCompares the two version numbers given by \fIversion1\fR and \fIversion2\fR.Returns -1 if \fIversion1\fR is an earlier version than \fIversion2\fR,0 if they are equal, and 1 if \fIversion1\fR is later than \fBversion2\fR..TP\fBpackage versions \fIpackage\fRReturns a list of all the version numbers of \fIpackage\fRfor which information has been provided by \fBpackage ifneeded\fRcommands..TP\fBpackage vsatisfies \fIversion1 version2\fRReturns 1 if scripts written for \fIversion2\fR will work unchangedwith \fIversion1\fR (i.e. \fIversion1\fR is equal to or greaterthan \fIversion2\fR and they both have the same major versionnumber), 0 otherwise..SH "VERSION NUMBERS".PPVersion numbers consist of one or more decimal numbers separatedby dots, such as 2 or 1.162 or 3.1.13.1.The first number is called the major version number.Larger numbers correspond to later versions of a package, withleftmost numbers having greater significance.For example, version 2.1 is later than 1.3 and version3.4.6 is later than 3.3.5.Missing fields are equivalent to zeroes: version 1.3 is thesame as version 1.3.0 and 1.3.0.0, so it is earlier than 1.3.1 or 1.3.0.2.A later version number is assumed to be upwards compatible withan earlier version number as long as both versions have the samemajor version number.For example, Tcl scripts written for version 2.3 of a package shouldwork unchanged under versions 2.3.2, 2.4, and 2.5.1.Changes in the major version number signify incompatible changes:if code is written to use version 2.1 of a package, it is not guaranteedto work unmodified with either version 1.7.3 or version 3.1..SH "PACKAGE INDICES".PPThe recommended way to use packages in Tcl is to invoke \fBpackage require\fRand \fBpackage provide\fR commands in scripts, and use the procedure\fBpkg_mkIndex\fR to create package index files.Once you've done this, packages will be loaded automaticallyin response to \fBpackage require\fR commands.See the documentation for \fBpkg_mkIndex\fR for details..SH KEYWORDSpackage, version
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -