Once the file has been loaded into the application's address space, one of two initialization procedures will be invoked in the new code. Typically the initialization procedure will add new commands to a Tcl interpreter. The name of the initialization procedure is determined by packageName and whether or not the target interpreter is a safe one. For normal interpreters the name of the initialization procedure will have the form pkg_Init, where pkg is the same as packageName except that the first letter is converted to upper case and all other letters are converted to lower case. For example, if packageName is foo or FOo, the initialization procedure's name will be Foo_Init.
If the target interpreter is a safe interpreter, then the name of the initialization procedure will be pkg_SafeInit instead of pkg_Init.
The initialization procedure must match the following prototype:
typedef int Tcl_PackageInitProc(Tcl_Interp *interp);The interp argument identifies the interpreter in which the package is to be loaded. The initialization procedure must return TCL_OK or TCL_ERROR to indicate whether or not it completed successfully; in the event of an error it should set interp->result to point to an error message. The result of the load command will be the result returned by the initialization procedure.
The target interpreter is the same as the invoking interpreter unless the interp option is specified. If interp is specified it gives the path name of an interpreter in which to load the package (see the interp manual entry for details on interpreter path names). It is not possible to unload or reload a package.
The actual loading of a file will only be done once for each fileName in an application. If a given fileName is loaded into multiple interpreters, then the first load will load the code and call the initialization procedure; subsequent loads will call the initialization procedure without loading the code again. It is not possible to unload or reload a package.
Copyright © 1995 Sun Microsystems, Inc. Copyright © 1995 Roger E. Critchlow Jr.