|
|
|
How Does Pike Find the Modules?
Here is a somewhat detailed explanation of exactly how Pike finds
the modules that you tell it to use. Normally you don't really need to
worry about all the details, except for what is needed to put your own
modules in a place where Pike can find them. But sometimes the details
can be important, for example if there are several modules with the
same name, but in different places, or if you want to do something
advanced and ingenious with modules.
Every module that is used somewhere in your program is loaded when
the program starts. It doesn't matter if you are importing the entire
module, or if you are just using a "qualified" name such as
smorglemod.fnordle() (that is, the method fnordle in
the module smorglemod). This is done even before
main is called. That the module is loaded means that the file
is read from disk, and the things in the module are made accessible to
your program.
When Pike loads a module with the name module-name,
Pike will look for a module with that name in the following
directories, in this order:
-
If the module-name was prefixed with a dot, in the
same directory as the program that used the module
-
In directories that have been imported with import
"directory-name"
-
In directories added with add_module_path
-
In directories specified with -M on the command line
-
In directories listed in the environment variable
PIKE_MODULE_PATH
-
In the directory with builtin modules, for example called
/usr/local/pike/0.7.97/lib/modules/ or
D:\Program Files\Pike\lib\pike\modules
In each of those directories, Pike will look for files or
subdirectories, in this order:
-
If there is a file called module-name.pmod, Pike
will load that file as a Pike program, clone it, and use the
newly-cloned object as a module.
-
If there is a directory called module-name.pmod,
Pike will create a module that has all the modules in that directory
as members. If there is a module called module (that is, with
the file name module.pmod, module.pmod.pike, or
module.pmod.so) in the directory
module-name.pmod, the members from that module will be
used instead of the modules actually present in the directory.
-
If there is a file called module-name.pmod.pike,
Pike will load that file as a Pike program, clone it, and use the
newly-cloned object as a module.
-
If we are on a Unix system, and if there is a file called
module-name.pmod.so, Pike will load that file with
load_module, clone it, and use the newly-cloned object as a
module. The file should be a dynamically linkable library of compiled
C or C++ code. (At the moment, this only works on Unix. For Windows
NT, modules written in C or C++ have to be statically linked.)
As we said before, you usually don't need to worry about these
details, except for what is needed to put your modules somewhere where
Pike can find them.
|
|