sleep.runtime
public class ScriptEnvironment extends Object implements Serializable
This class contains methods for accessing the data stack, return value of a function, and the environment hashtable for a script. In sleep each ScriptInstance has a ScriptEnvironment object associated with it. Most of the functions in this class are used internally by sleep.
For the developers purposes, this class is your gateway into the runtime environment of a script.
If you use the evaluate methods to evaluate a snippet of code, they will be evaluated as if they were part of the script file that this ScriptEnvironment represents.
The Hashtable environment contains references for all of the loaded bridges this script has access to. Every function, predicate, and operator is specified in the environment hashtable. To force scripts to share this information use setEnvironment(Hashtable) and pass the same instance of Hashtable that other scripts are using.
This class is instantiated by sleep.runtime.ScriptInstance.
See Also: ScriptLoader ScriptInstance
Nested Class Summary | |
---|---|
protected static class | ScriptEnvironment.Context |
protected static class | ScriptEnvironment.ExceptionContext |
Field Summary | |
---|---|
protected Stack | context |
protected Stack | contextStack |
protected ScriptEnvironment.ExceptionContext | currentHandler |
protected String | debugString |
protected Hashtable | environment the environment hashtable that contains all of the functions, predicates, operators, and "environment keywords" this
script has access to. |
protected Stack | environmentStack the runtime data stack for this environment |
protected Object | errorMessage stored error message... |
protected Stack | exhandlers |
protected int | findex |
protected ArrayList | frames |
static int | FLOW_CONTROL_BREAK request a break out of the current loop |
static int | FLOW_CONTROL_CONTINUE adding a continue keyword as people keep demanding it |
static int | FLOW_CONTROL_DEBUG a special case for debugs and such |
static int | FLOW_CONTROL_NONE currently no flow control change has been requested |
static int | FLOW_CONTROL_RETURN request a return from the current function |
static int | FLOW_CONTROL_THROW adding a throw keyword -- sleep is now useable :) |
static int | FLOW_CONTROL_YIELD adding a yield keyword |
protected HashMap | metadata |
protected Stack | metaStack |
protected boolean | moreHandlers |
protected int | request |
protected Scalar | rv |
protected ScriptInstance | self the script instance that this is the environment for |
protected Stack | sources how many stacks does this damned class include? |
Constructor Summary | |
---|---|
ScriptEnvironment() Not recommended that you instantiate a script environment in this way | |
ScriptEnvironment(Hashtable env, ScriptInstance myscript) Instantiate a new script environment with the specified environment (can be shared), and the specified ScriptInstance |
Method Summary | |
---|---|
void | addToContext(Block b, Step s) |
Scalar | checkError() once an error is checked using this function, it is cleared, the orignal error message is returned as well |
void | clearReturn() Clears the return value from the last executed function. |
void | CreateFrame() |
Scalar | evaluateExpression(String code) evaluates an expression |
Scalar | evaluateOldContext() |
Scalar | evaluateParsedLiteral(String code) evaluates the passed in code as if it was a sleep parsed literal |
boolean | evaluatePredicate(String code) evaluates a predicate condition |
Scalar | evaluateStatement(String code) evaluate a full blown statement... probably best to just load a script at this point |
void | flagError(Object message) A utility for bridge writers to flag an error. flags an error that script writers can then check for with checkError().
|
void | flagReturn(Scalar value, int type_of_flow) |
void | FrameResult(Scalar value) kills the current frame and if there is a parent frame pushes the specified value on to it |
Object | getContextMetadata(Object key) Returns the data associated with the particular key for this context. |
Object | getContextMetadata(Object key, Object default_value) Returns the data associated with the particular key for this context. |
Stack | getCurrentFrame() |
String | getCurrentSource() obtain the filename of the current source of execution |
String | getDebugString() |
Hashtable | getEnvironment()
Returns the environment for this script.
|
Stack | getEnvironmentStack() returns the environment stack used for temporary calculations and such. |
Block | getExceptionHandler() preps and returns the current exception handler... |
Scalar | getExceptionMessage() if there is no handler, we'll just get the message which will clear the thrown message as well |
FilterEnvironment | getFilterEnvironment(String env) |
int | getFlowControlRequest() |
Function | getFunction(String func) |
Environment | getFunctionEnvironment(String env) |
Operator | getOperator(String oper) |
Predicate | getPredicate(String name) |
PredicateEnvironment | getPredicateEnvironment(String env) |
Scalar | getReturnValue() |
Scalar | getScalar(String key) returns a scalar from this scripts environment |
ScriptInstance | getScriptInstance() returns a reference to the script associated with this environment |
ScriptVariables | getScriptVariables() returns the variable manager for this script |
boolean | hasFrame() |
void | installExceptionHandler(ScriptEnvironment.ExceptionContext exc) |
void | installExceptionHandler(Block owner, Block handler, String varname) |
boolean | isDebugInterrupt() |
boolean | isExceptionHandlerInstalled() |
boolean | isResponsible(Block block) |
boolean | isReturn() |
boolean | isThrownValue() |
void | KillFrame() |
void | loadContext(Stack _context, HashMap _metadata) |
ScriptEnvironment.ExceptionContext | popExceptionContext() |
void | popSource() remove the latest source information from the source stack |
void | pushSource(String s) push source information onto the source stack |
void | putScalar(String key, Scalar value) puts a scalar into this scripts environment (global scope) |
void | resetEnvironment() Resets the script environment to include clearing the return of all flags (including thrown exceptions) |
Stack | saveContext() |
void | setContextMetadata(Object key, Object value) Use this function to save some meta data for this particular closure context, passing null for value will
remove the key from the metadata for this context |
void | setEnvironment(Hashtable h) Sets the environment Hashtable this script is to use. |
void | showDebugMessage(String message) fires this debug message via a runtime warning complete with line number of current step |
String | toString() |