AutoLoad

AutoLoad — allows for run-time symbol lookup.

Syntax

AutoLoad ("pattern", `action)

		

Arguments

pattern
A shell style pattern.
action
An action to be taken when the pattern is matched.

Returns

The _auto_load_alist_, which is a list of all currently stored AutoLoad rules. Each rule is itself formatted as a list. This is the _auto_load_alist_ syntax:

((pattern action_func action_arg ...) ...)

The members of each rule list are as follows:

pattern
The AutoLoad pattern parameter.
action_func
The function specified in the AutoLoad action parameter.
action_arg
The function argument(s) specified in the AutoLoad action parameter.

For example, the AutoLoad rules in AutoLoadLib.g (at the time of this writing) would be returned as follows:

(("P[Tthg]*" DllLoad "libgammaph.so") ("gl[A-Z]*" DllLoad "libgammagl.so")
 ("GLUT_*" DllLoad "libgammagl.so") ("GLU_*" DllLoad "libgammagl.so")
 ("GL_*" DllLoad "libgammagl.so") ("ASCII_*" DllLoad "libgammamgl.so")
 ("KB_*" DllLoad "libgammamgl.so") ("GM_*" DllLoad "libgammamgl.so")
 ("EVT_*" DllLoad "libgammamgl.so") ("[mM][gG][lL]*" DllLoad "libgammamgl.so")
 ("[gG]tk*" DllLoad "gammagtk.so"))

Description

This function gives Gamma a way to look up symbols during run-time. If Gamma comes across an undefined symbol while executing a program, and if the symbol matches the pattern, then Gamma executes the action. Normally the action is either a direct definition of the symbol, or an attempt to load a DLL that defines the symbol, using DllLoad, for example.

The available patterns are as follows:

  • matches any number of characters, including zero.
  • [cmatches a single character which is a member of the set contained within the square brackets.
  • [^cmatches any single character which is not a member of the set contained within the square brackets.
  • matches a single character.
  • {xx,yymatches either of the simple strings contained within the braces.
  • \c (a backslash followed by a character) - matches that character.
[Note]

This function is not part of the base Gamma executable. It is provided by a Gamma library AutoLoadLib.g which can be accessed using the Gamma require function like this:

require ("/usr/cogent/require/AutoLoadLib.g");

Example

[Note]
  • In this example, we use the ClearAutoLoad function to clear the AutoLoad list just to make the steps easier to follow.
  • Once a library is loaded or a symbol is defined, Gamma no longer sends a "Looking for symbol" message.
  • Notice how although NoAutoLoad and ClearAutoLoad remove a pattern from future consideration, any symbols defined or any libraries loaded before they were called remain valid.
Gamma> require ("/usr/cogent/require/AutoLoadLib.g");
t
Gamma> ClearAutoLoad();
nil
Gamma> AutoLoad ("[gG]tk*", `DllLoad ("gammagtk.so"));
(("[gG]tk*" DllLoad "gammagtk.so"))
Gamma> gtk_arg_new;
Looking for gtk_arg_new
(defun gtk_arg_new (arg_type) ...)
Gamma> gtk_main;
(defun gtk_main () ...)
Gamma> testvar;
Looking for testvar
Symbol is undefined: testvar
debug 1> (Ctrl - D)
Gamma> AutoLoad("testvar", `testvar = 5);
(("testvar" setq testvar 5) ("[gG]tk*" DllLoad "gammagtk.so"))
Gamma> testvar;
Looking for testvar
5
Gamma> NoAutoLoad("testvar");
(("[gG]tk*" DllLoad "gammagtk.so"))
Gamma> testvar;
5
Gamma> ClearAutoLoad();
nil
Gamma> gtk_main;
(defun gtk_main () ...)
Gamma> gtk_false;
(defun gtk_false () ...)
Gamma>  
	

See Also

ClearAutoLoad, NoAutoLoad, DllLoad