sleep.interfaces
Interface Loadable

All Known Implementing Classes:
ConsoleImplementation

public interface Loadable

A loadable bridge is used to perform actions on scripts when they are loaded and unloaded. Loadable bridges by themselves do not add anything to the sleep language at all. In conjunction with a ScriptLoader loadable bridges make it easy to process the environment of scripts as they are loaded and unloaded.

A loadable bridge is installed into the language by adding it to a script loader class.

An example of a loadable bridge in action:

 public class MyBridge implements Loadable
 {
    public void scriptLoaded(ScriptInstance script)
    {
       Hashtable environment = script.getScriptEnvironment().getEnvironment();
       environment.put("&function",  new MyFunction());
       environment.put("-predicate", new MyPredicate());
    }
 
    public void scriptUnloaded(ScriptInstance script)
    {
    }
 
    private static class MyFunction implements Function
    {
       public Scalar evaluate(String name, ScriptInstance si, Stack args)
       {
           // code for MyFunction
       }
    }
 
    private static class MyPredicate implements Predicate
    {
       public boolean decide(String name, ScriptInstance si, Stack args)
       {
           // code for MyPredicate
       }
    }
 }
 

An example of adding the above loadable bridge to a script loader:

 ScriptLoader loader = new ScriptLoader()
 loader.addSpecificBridge(new MyBridge());
 

Bottom line: Loadable bridges ARE used to install other bridges into a script environment. Using a loadable bridge is the easiest way to make sure actions are always performed on a script as it loads. Loadable bridges in conjunction with a script loader are used to perform cleanup actions when a script is unloaded.

See Also:
ScriptLoader

Method Summary
 void scriptLoaded(ScriptInstance script)
          called when a script is loaded
 void scriptUnloaded(ScriptInstance script)
          called when a script is unloaded
 

Method Detail

scriptLoaded

void scriptLoaded(ScriptInstance script)
called when a script is loaded


scriptUnloaded

void scriptUnloaded(ScriptInstance script)
called when a script is unloaded