Seth Woolley's Man Viewer

Manual for load - man n load

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

load(7,n)(n)                      Tcl Built-In Commands                     load(7,n)(n)



NAME
       load(7,n) - Load machine code and initialize new commands.

SYNOPSIS
       load(7,n) fileName
       load(7,n) fileName packageName
       load(7,n) fileName packageName interp


DESCRIPTION
       This  command  loads  binary  code  from  a file(1,n) into the application's
       address space and calls an initialization procedure in(1,8) the  package  to
       incorporate  it  into an interpreter.  fileName is the name of the file(1,n)
       containing the code;  its exact form varies from system to  system  but
       on  most  systems  it  is  a  shared  library, such as a .so file(1,n) under
       Solaris or a DLL under Windows.  packageName is the name of  the  pack-
       age,  and  is  used to compute the name of an initialization procedure.
       interp is the path name of the interpreter into which to load(7,n) the pack-
       age (see the interp manual entry for details); if(3,n) interp is omitted, it
       defaults to the interpreter in(1,8) which the load(7,n) command was invoked.

       Once the file(1,n) has been loaded into the application's address space, one
       of two initialization procedures will be invoked in(1,8) the new code.  Typ-
       ically 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(3,n)  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
       pkg_SafeInit  function should be written carefully, so that it initial-
       izes the safe interpreter only with partial functionality  provided  by
       the  package  that is safe for use by untrusted code. For more informa-
       tion on Safe-Tcl, see the safe manual entry.

       The initialization procedure must match the following prototype:  type-
       def  int  Tcl_PackageInitProc(Tcl_Interp  *interp); The interp argument
       identifies the interpreter in(1,8) 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(1,8) the event of an error(8,n)  it
       should  set(7,n,1 builtins) the interpreter's result to point to an error(8,n) message.  The
       result of the load(7,n) command will be the result returned by the  initial-
       ization procedure.

       The  actual  loading of a file(1,n) will only be done once for each fileName
       in(1,8) an application.  If a given fileName is loaded into multiple  inter-
       preters,  then  the first load(7,n) will load(7,n) the code and call the initial-
       ization procedure;  subsequent load(7,n)s will call the initialization  pro-
       cedure without loading the code again.  It is not possible to unload or
       reload a package.

       The load(7,n) command also supports packages that are statically linked with
       the  application, if(3,n) those packages have been registered by calling the
       Tcl_StaticPackage procedure.  If fileName  is  an  empty  string(3,n),  then
       packageName must be specified.

       If packageName is omitted or specified as an empty string(3,n), Tcl tries to
       guess the name of the package.  This may be done differently on differ-
       ent  platforms.   The  default  guess, which is used on most UNIX plat-
       forms, is to take the last element of fileName,  strip  off  the  first
       three  characters if(3,n) they are lib, and use any following alphabetic and
       underline characters as the module name.  For example, the command load(7,n)
       libxyz4.2.so  uses the module name xyz and the command load(7,n) bin/last.so
       {} uses the module name last.

       If fileName is an empty string(3,n), then  packageName  must  be  specified.
       The  load(7,n)  command  first searches for a statically loaded package (one
       that has been registered by calling the Tcl_StaticPackage procedure) by
       that  name;  if(3,n)  one is found, it is used.  Otherwise, the load(7,n) command
       searches for a dynamically loaded package by that name, and uses it  if(3,n)
       it  is found.  If several different files have been load(7,n)ed with differ-
       ent versions of the package, Tcl picks the file(1,n) that was loaded  first.


PORTABILITY ISSUES
       Windows
              When  a  load(7,n)  fails  with "library not found" error(8,n), it is also
              possible that a dependent library was not  found.   To  see  the
              dependent  libraries,  type  ``dumpbin -imports <dllname>'' in(1,8) a
              DOS console(4,n) to see what the library must import.  When loading a
              DLL  in(1,8)  the  current directory, Windows will ignore ``./'' as a
              path specifier and use  a  search  heuristic  to  find  the  DLL
              instead.  To avoid this, load(7,n) the DLL with
                  load(7,n) [file(1,n) join(1,n) [pwd(1,n,1 builtins)] mylib.DLL]


BUGS
       If  the  same  file(1,n) is load(7,n)ed by different fileNames, it will be loaded
       into the process's address space multiple times.  The behavior of  this
       varies  from  system  to  system (some systems may detect the redundant
       loads, others may not).


SEE ALSO
       info(1,5,n) sharedlibextension, Tcl_StaticPackage(3), safe(n)


KEYWORDS
       binary code, loading, safe interpreter, shared library



Tcl                                   7.5                              load(7,n)(n)

References for this manual (incoming links)