sleep.runtime
Class ScriptInstance

java.lang.Object
  extended bysleep.runtime.ScriptInstance
All Implemented Interfaces:
Serializable

public class ScriptInstance
extends Object
implements Serializable

Every piece of information related to a loaded script. This includes the scripts runtime environment, code in compiled form, variable information, and listeners for runtime issues.

See Also:
Serialized Form

Field Summary
protected  ScriptEnvironment environment
          The script environment which contains all of the runtime info for a script
protected  boolean loaded
          true by default, indicates wether or not the script is loaded.
protected  String name
          the name of this script
protected  Block script
          The compiled sleep code for this script, the ScriptLoader will set this value upon loading a script.
protected  ScriptVariables variables
          The script variables which contains all of the variable information for a script
protected  LinkedList watchers
          A list of listeners watching for a runtime error
 
Constructor Summary
ScriptInstance()
          Constructs a new script instance
ScriptInstance(Hashtable environmentToShare)
           
ScriptInstance(Variable varContainerToUse, Hashtable environmentToShare)
          Constructs a script instance, if either of the parameters are null a default implementation will be used.
 
Method Summary
 void addWarningWatcher(RuntimeWarningWatcher w)
          Register a runtime warning watcher listener.
 Scalar callFunction(String funcName, Stack parameters)
          Calls a subroutine/built-in function using this scripts
 void fireWarning(String message, int line)
          Fire a runtime script warning
 String getName()
          Returns the name of this script (typically a full pathname) as a String
 Block getRunnableBlock()
          Returns the compiled form of this script
 ScriptEnvironment getScriptEnvironment()
          Returns this scripts runtime environment
 ScriptVariables getScriptVariables()
          Returns the variable container used by this script
 void installBlock(Block _script)
          Install a block as the compiled script code
 boolean isLoaded()
          Returns wether or not this script is loaded.
 void removeWarningWatcher(RuntimeWarningWatcher w)
          Removes a runtime warning watcher listener
 void runScript()
          Executes this script, should be done first thing once a script is loaded
 void setName(String sn)
          Sets the name of this script
 void setScriptVariables(ScriptVariables v)
          Sets the variable container to be used by this script
 void setUnloaded()
          Flag this script as unloaded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected String name
the name of this script


loaded

protected boolean loaded
true by default, indicates wether or not the script is loaded. Once unloaded this variable must be flagged to false so the bridges know data related to this script is stale


watchers

protected LinkedList watchers
A list of listeners watching for a runtime error


environment

protected ScriptEnvironment environment
The script environment which contains all of the runtime info for a script


variables

protected ScriptVariables variables
The script variables which contains all of the variable information for a script


script

protected Block script
The compiled sleep code for this script, the ScriptLoader will set this value upon loading a script.

Constructor Detail

ScriptInstance

public ScriptInstance(Hashtable environmentToShare)

ScriptInstance

public ScriptInstance(Variable varContainerToUse,
                      Hashtable environmentToShare)
Constructs a script instance, if either of the parameters are null a default implementation will be used. By specifying the same shared Variable and Hashtable containers for all scripts, scripts can be made to share variables and environment information


ScriptInstance

public ScriptInstance()
Constructs a new script instance

Method Detail

installBlock

public void installBlock(Block _script)
Install a block as the compiled script code


getScriptEnvironment

public ScriptEnvironment getScriptEnvironment()
Returns this scripts runtime environment


setScriptVariables

public void setScriptVariables(ScriptVariables v)
Sets the variable container to be used by this script


getScriptVariables

public ScriptVariables getScriptVariables()
Returns the variable container used by this script


getName

public String getName()
Returns the name of this script (typically a full pathname) as a String


setName

public void setName(String sn)
Sets the name of this script


runScript

public void runScript()
Executes this script, should be done first thing once a script is loaded


getRunnableBlock

public Block getRunnableBlock()
Returns the compiled form of this script


callFunction

public Scalar callFunction(String funcName,
                           Stack parameters)
Calls a subroutine/built-in function using this scripts


setUnloaded

public void setUnloaded()
Flag this script as unloaded


isLoaded

public boolean isLoaded()
Returns wether or not this script is loaded. If it is unloaded it should be removed from data structures and its modifications to the environment should be ignored


addWarningWatcher

public void addWarningWatcher(RuntimeWarningWatcher w)
Register a runtime warning watcher listener. If an error occurs while the script is running these listeners will be notified


removeWarningWatcher

public void removeWarningWatcher(RuntimeWarningWatcher w)
Removes a runtime warning watcher listener


fireWarning

public void fireWarning(String message,
                        int line)
Fire a runtime script warning