Copyright | (c) Hampus Ram 2003-2004 Gabor Greif 2012 |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | [email protected] |
Stability | experimental |
Portability | non-portable (ghc >= 7.6 only) |
Safe Haskell | None |
Language | Haskell98 |
System.Plugins.DynamicLoader
Description
A module that implements dynamic loading. You can load and use GHC object files and packages dynamically at runtime.
- data DynamicModule
- dm_path :: DynamicModule -> FilePath
- data DynamicPackage
- dp_path :: DynamicPackage -> FilePath
- data DynamicArchive
- da_path :: DynamicArchive -> FilePath
- addDLL :: String -> IO ()
- loadModule :: String -> Maybe FilePath -> Maybe String -> IO DynamicModule
- loadModuleFromPath :: FilePath -> Maybe FilePath -> IO DynamicModule
- loadPackage :: String -> Maybe FilePath -> Maybe String -> Maybe String -> IO DynamicPackage
- loadPackageFromPath :: FilePath -> IO DynamicPackage
- loadArchiveFromPath :: FilePath -> IO DynamicArchive
- unloadModule :: DynamicModule -> IO ()
- unloadPackage :: DynamicPackage -> IO ()
- unloadArchive :: DynamicArchive -> IO ()
- loadFunction :: DynamicModule -> String -> IO a
- loadQualifiedFunction :: String -> IO a
- resolveFunctions :: IO ()
Documentation
data DynamicModule Source #
dm_path :: DynamicModule -> FilePath Source #
data DynamicPackage Source #
dp_path :: DynamicPackage -> FilePath Source #
data DynamicArchive Source #
da_path :: DynamicArchive -> FilePath Source #
addDLL :: String -> IO () Source #
Dynamically load a shared library (DLL or .so). A shared library can't be unloaded using this interface, if you need it use System.Posix.DynamicLinker instead.
loadModule :: String -> Maybe FilePath -> Maybe String -> IO DynamicModule Source #
Load a module given its name (for instance Data.FiniteMap
), maybe a
path to the base directory and maybe a file extension. If no such path
is given the current working directory is used and if no file suffix
is given "o" is used.
If we have our module hierarchy in /usr/lib/modules
and we want to
load the module Foo.Bar
located in /usr/lib/modules/Foo/Bar.o
we
could issue the command:
loadModule "Foo.Bar" (Just "/usr/lib/modules") Nothing
If our current directory was /tmp
and we wanted to load the module
Foo
located in the file /tmp/Foo.obj
we would write:
loadModule "Foo" Nothing (Just "obj")
If it cannot load the object it will throw an exception.
loadModuleFromPath :: FilePath -> Maybe FilePath -> IO DynamicModule Source #
Load a module given its full path and maybe a base directory to use in figuring out the module's hierarchical name. If no base directory is given, it is set to the current directory.
For instance if one wants to load module Foo.Bar
located in
/usr/modules/Foo/Bar.o
one would issue the command:
loadModuleFromPath "/usr/modules/Foo/Bar.o" (Just "/usr/modules")
If it cannot load the object it will throw an exception.
loadPackage :: String -> Maybe FilePath -> Maybe String -> Maybe String -> IO DynamicPackage Source #
Load a GHC package such as "base" or "text". Takes the package name, maybe a path to the packages, maybe a package prefix and maybe a package suffix.
Path defaults to the current directory, package prefix to "HS" and package suffix to "o".
This function also loads accompanying cbits-packages. I.e. if you load
the package base
located in /usr/modules
using HS
and o
as
prefix and suffix, loadPackage
will also look for the file
/usr/modules/HSbase_cbits.o
and load it if present.
If it fails to load a package it will throw an exception. You will need to resolve functions before you use any functions loaded.
loadPackageFromPath :: FilePath -> IO DynamicPackage Source #
Load a GHC package such as "base" or "text". Takes the full path to the package.
This function also loads accompanying cbits-packages. I.e. if you load
the package /usr/modules/HSbase.o
it will deduce that o
is the
suffix and loadPackageFromPath
will then also look for the file
/usr/modules/HSbase_cbits.o
and load it if present.
If it fails to load a package it will throw an exception. You will need to resolve functions before you use any functions loaded.
loadArchiveFromPath :: FilePath -> IO DynamicArchive Source #
Load an archive of GHC modules. Recent versions of GHC store packages as archives.
If it fails to load the archive it will throw an exception. You will need to resolve functions before you use any functions loaded.
unloadModule :: DynamicModule -> IO () Source #
Unload a previously loaded module. If it cannot unload it an exception will be thrown.
unloadPackage :: DynamicPackage -> IO () Source #
Unload a package (such as base
) and its cbits-package (if
any). Throws an exception if any unloading fails.
unloadArchive :: DynamicArchive -> IO () Source #
Unload an archive. Throws an exception if any unloading fails.
loadFunction :: DynamicModule -> String -> IO a Source #
Load a function from a given module. If the function can't be found an
exception will be thrown. You should have called resolveFunctions
before
you call this.
Beware that this function isn't type-safe in any way!
loadQualifiedFunction :: String -> IO a Source #
Load a function from package (or module) given the fully qualified
name (e.g. Data.FiniteMap.emptyFM
). If the function can't be found an
exception will be thrown. You should have called resolveFunctions
before you call this.
You must take care that you load the function qualified with the name
of the module it's defined in! You can for instance not load
Data.Bool.not
because it is only reexported in that module (from
GHC.Base).
Beware that this function isn't type-safe in any way!
resolveFunctions :: IO () Source #
Resolve all loaded functions. Should be called before any functions are loaded. If it is unable to resolve all functions it will throw an exception.