Classes | |
class | ScriptTimer |
Public Member Functions | |
float | getRunTime () |
boolean | isParsed () |
int | traceDelay () |
void | traceDelay (int delay) |
boolean | isTraceModeOn () |
void | traceModeOn () |
void | traceModeOff () |
void | setTimeLimit (float limit) |
boolean | isStopped () |
boolean | isPaused () |
boolean | isRunning () |
synchronized void | stop () |
synchronized void | waitFor (int time) |
synchronized void | resume () |
Result | evaluate () |
Result | evaluate_ () throws EvaluationException |
Result | finalResult () |
void | throwSyntaxException (ErrorType etype, Token token) throws SyntaxException |
void | throwEvaluationException (ErrorType etype, Token token) throws EvaluationException |
void | fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token) |
void | fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token, Object extra) |
void | fireEvent (Class<?extends ScriptEvent > eventClass, ErrorType etype, Token token, Object[] extra) |
boolean | addListener (Object listener) |
boolean | removeListener (Object listener) |
String | getLastIdentifier () |
void | storeVariable (Variable var) |
void | storeVariable (String identifier, Object value) |
synchronized Variable[] | getStoredVariables () |
void | clearVariables () |
Variable | getVariable (String identifier) |
Variable | getVariable (Variable var) |
Script (String line) | |
Script (String[] lines) | |
Script (List< String > lines) | |
void | parse () |
void | parse_ () throws SyntaxException |
float | getParseTime () |
void | setCode (List< String > lines) |
void | setCode (String[] lines) |
void | setCode (String line) |
String[] | getCode () |
void | printTokens (String title, List< Token > tokens) |
void | printProgram (String title, List< ScriptStep > steps) |
Static Public Member Functions | |
static void | defaultTimeLimit (float defaultTimeLimit) |
static double | defaultTimeLimit () |
This class is responsible for managing all the actions necessary to evaluate an expression or algorithm. It will use the Tokenizer, Postix and Compiler classes to create a list of ScriptStep(s) which it will then try to evaluate.
boolean org.qscript.Script.addListener | ( | Object | listener | ) |
Add an event listener to this script.
The listener must have a method annotated with this method must have a single parameter of type ScriptEvent.
listener | the event receiver |
void org.qscript.Script.clearVariables | ( | ) |
Remove all variables from the data store
|
static |
Set the default time limit (seconds) for all subsequent scripts. This is used to stop the script evaluation taking longer than expected. It is useful in the event of an infinite loop.
defaultTimeLimit | the maximum time in seconds |
|
static |
Get the default script evaluation time limit.
void org.qscript.Script.fireEvent | ( | Class<?extends ScriptEvent > | eventClass, |
ErrorType | etype, | ||
Token | token | ||
) |
Worker method to create and forward script events to listeners.
eventClass | the event class we want to create |
etype | the error type (if the event is caused by an error) |
token | the token that is the source of the event |
void org.qscript.Script.fireEvent | ( | Class<?extends ScriptEvent > | eventClass, |
ErrorType | etype, | ||
Token | token, | ||
Object | extra | ||
) |
Worker method to create and forward script events to listeners.
eventClass | the event class we want to create |
etype | the error type (if the event is caused by an error) |
token | the token that is the source of the event |
extra | one additional object depending on event and error types |
void org.qscript.Script.fireEvent | ( | Class<?extends ScriptEvent > | eventClass, |
ErrorType | etype, | ||
Token | token, | ||
Object[] | extra | ||
) |
Worker method to create and forward script events to listeners.
eventClass | the event class we want to create |
etype | the error type (if the event is caused by an error) |
token | the token that is the source of the event |
extra | additional objects depending on event and error types |
String [] org.qscript.Script.getCode | ( | ) |
Get the lines of code for this script.
float org.qscript.Script.getParseTime | ( | ) |
Get the time it took parse the script ready for evaluation
synchronized Variable [] org.qscript.Script.getStoredVariables | ( | ) |
Get an array of all the variables stored in the data store.
This is slow because it has to be synchronised with the script. It is better to create your own data store in the main sketch and listen for DataStoreEvents.
Variable org.qscript.Script.getVariable | ( | String | identifier | ) |
Get a simple variable based on the identifier.
identifier |
Get a simple variable from the store.
var |
boolean org.qscript.Script.isParsed | ( | ) |
See if the script has been successfully parsed
boolean org.qscript.Script.isPaused | ( | ) |
Return true of the script has been paused during evaluation.
boolean org.qscript.Script.isRunning | ( | ) |
Is the evaluation still going on?
boolean org.qscript.Script.isStopped | ( | ) |
Return true of the script has stopped evaluation.
boolean org.qscript.Script.isTraceModeOn | ( | ) |
Determines whether this script should fire TraceEvents or not.
If you switch tracing on then the time limit is ignored because it is assumed that you are taking control and will end evaluation with the stop() method when needed.
If you are switching off tracing then the timer is reset and the time limit set equal to the default time limit.
You can adjust the trace speed the with traceDelay(int) method.
activate | use true to turn on trace events Find out whether the trace is on or not. |
boolean org.qscript.Script.removeListener | ( | Object | listener | ) |
Remove an event listener to this script.
listener | the event receiver |
synchronized void org.qscript.Script.resume | ( | ) |
This will resume a paused script. Use this to resume a script from the wait state
void org.qscript.Script.setCode | ( | List< String > | lines | ) |
Set the script lines for this script.
The script will need to be initialized before evaluating.
lines | the code as a list of strings |
void org.qscript.Script.setCode | ( | String[] | lines | ) |
Set the script lines for this script.
The script will need to be initialized before evaluating.
lines | the code as an array of strings |
void org.qscript.Script.setCode | ( | String | line | ) |
Set the script line for this script.
The script will need to be initialized before evaluating.
line | single line of code |
void org.qscript.Script.setTimeLimit | ( | float | limit | ) |
Sets the time limit for this script. The script will be stopped if this time is reached.
limit | in seconds |
synchronized void org.qscript.Script.stop | ( | ) |
Stop the evaluation - result is undefined.
void org.qscript.Script.storeVariable | ( | Variable | var | ) |
Save a variable to the current score. Only fire an event if the script is running and returns a copy of the variable to avoid concurrency issues
var |
void org.qscript.Script.storeVariable | ( | String | identifier, |
Object | value | ||
) |
Load the store with a new variable based on the provided identifier and value. The identifier will be prepended with $ if necessary.
identifier | the identifier e.g. $x |
value | the value. |
void org.qscript.Script.throwEvaluationException | ( | ErrorType | etype, |
Token | token | ||
) | throws EvaluationException |
Focal point for all evaluation exception throwing.
etype | the error type |
token | token where the exception occured |
SyntaxException |
void org.qscript.Script.throwSyntaxException | ( | ErrorType | etype, |
Token | token | ||
) | throws SyntaxException |
Focal point for all syntax exception throwing.
etype | the error type |
token | token where the exception occured |
SyntaxException |
int org.qscript.Script.traceDelay | ( | ) |
Get the delay time (in milliseconds) after token has been parsed.
void org.qscript.Script.traceDelay | ( | int | delay | ) |
Set the delay (milliseconds) between processing tokens It does not determine if the trace mode is on or off, this should be done with
traceModeOn() traceModeOff()
delay | the traceDelay (in milliseconds) to set |
void org.qscript.Script.traceModeOff | ( | ) |
Switches trace mode off
void org.qscript.Script.traceModeOn | ( | ) |
Switches the trace mode on. This causes a delay between evaluation of token. The delay time is not included in the script runtime so will not cause the script to time out.
synchronized void org.qscript.Script.waitFor | ( | int | time | ) |
Will cause the script to pause for the specified time in milliseconds or until resume() method is called, whichever is the sooner. If the parameter time is zero then the script must be resumed by the user.
The wait time is not included in the runtime so will not cause the script to timeout.
If the script is already in a paused state or has stopped then this method does nothing.
It is also called by the script WAAIT operator
time | timeout in milliseconds |