next up previous contents index
Next: 2.12.3 module Up: 2.12 Class reference Previous: 2.12.1 vclass   Contents   Index


2.12.2 mclass

The mclass class uses the singleton pattern to provide an application-wide interface for loading modules. Additionally, the mclass:modules method makes it possible to find out what modules are currently loaded.

Table 2.13: mclass summary
Input(s)
Method
Output(s)
Description
Class-context methods
-
new
instance
Constructor.
-
singleton
instance
Get an mclass singleton instance.
Instance-context methods
modname
load
-
Load a module.
modname
unload_notify
-
Notify the mclass singleton of a module unload.
-
modules
modules
Get loaded modules.

modname load -:
Input(s):
modname:
The name of a module.
Output(s):
None.
Error(s):
invalidfileaccess.
ioerror.
limitcheck.
rangecheck.
stackunderflow.
typecheck.
undefinedfilename.
Description:
Load the module named modname, and define the module name as the module in currentdict.
Example(s):
onyx:0> $modclopt mclass:singleton:load
onyx:0>
o
- modules modules:
Input(s):
None.
Output(s):
modules:
A dictionary of module names associated with module instances.
Error(s):
None.
Description:
Get a dictionary of loaded modules.
Example(s):
onyx:0> mclass:singleton:modules 1 sprint
<$modprompt -instance=$module- $modclopt -instance=$module->
onyx:0>
- new instance:
Input(s):
None.
Output(s):
instance:
An instance of class.
Error(s):
typecheck.
Description:
Constructor.
Example(s):
onyx:0> mclass:new 1 sprint
-instance-
onyx:0>
- singleton instance:
Input(s):
None.
Output(s):
instance:
An mclass singleton instance.
Error(s):
None.
Description:
Get an mclass singleton instance.
Example(s):
onyx:0> mclass:singleton 1 sprint
-instance=$mclass-
onyx:0>
modname unload_notify -:
Input(s):
modname:
The name of a module.
Output(s):
None.
Error(s):
stackunderflow.
typecheck.
Description:
Notify the mclass singleton of a module unload. This method is called by the module:unload method, and isn't normally called directly by application code.
Example(s):
Following is the implementation of module:unload:
# Unload the module.
#
#instance#
#- unload -
$unload {
    # Evaluate the pre-unload hook.
    ,pre_unload_hook eval

    # Iteratively undefine the module definitions, as recorded in the mdefs
    # dict.
    ,mdefs {
        exch 0 get
        #defdict #defname
        undef
    } foreach

    # Evaluate the post-unload hook.
    ,post_unload_hook eval

    # Notify mclass_singleton of the unload.
    ,name ,mclass_singleton:unload_notify
} bind


next up previous contents index
Next: 2.12.3 module Up: 2.12 Class reference Previous: 2.12.1 vclass   Contents   Index
Jason Evans 2005-03-16