Package VASSAL.script
Class ExpressionInterpreter
java.lang.Object
bsh.Interpreter
VASSAL.script.AbstractInterpreter
VASSAL.script.ExpressionInterpreter
- All Implemented Interfaces:
bsh.ConsoleInterface,Serializable,Runnable,RecursionLimiter.Loopable
A BeanShell Interpreter customised to evaluate a single Vassal
expression containing Vassal property references.
All traits with the same expression will share the same Interpreter
Each ExpressionInterpreter has 2 levels of NameSpace:
1. Top level is a single global NameSpace that contains utility methods
available to all ExpressionInterpreters. It is the parent of all
level 2 NameSpaces.
2. Level 2 is a NameSpace for each unique expression that contains the
parsed expression. All expressions in all traits that are the same
will use the one Expression NameSpace.
- See Also:
- Serialized Form
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected bsh.NameSpaceprotected static Stringprotected static Stringprotected static Stringprotected static Stringprotected PropertySourceprotected static Stringprotected static Stringprotected static bsh.NameSpaceFields inherited from class VASSAL.script.AbstractInterpreter
myNameSpaceFields inherited from class bsh.Interpreter
DEBUG, evalOnly, interactive, LOCALSCOPING, TRACE, VERSION -
Constructor Summary
ConstructorsConstructorDescriptionExpressionInterpreter(String expr)Private constructor to build an ExpressionInterpreter. -
Method Summary
Modifier and TypeMethodDescriptionevaluate()evaluate(PropertySource ps)Evaluate the expression, setting the value of any undefined values to the matching Vassal property value.evaluate(PropertySource ps, boolean localized)Return the current expressiongetLocalizedProperty(String name)getMapProperty(String propertyName, String mapName)getProperty(String name)Callbacks from BeanShell Expressions to VassalgetZoneProperty(String propertyName, String zoneName)getZoneProperty(String propertyName, String zoneName, String mapName)protected voidInitialise the static elements of this class.protected static StringsumLocation(String property, PropertySource ps)SumLocation(property) function Total the value of the named property in all counters in the same location as the specified piece.sumStack(String property, PropertySource ps)SumStack(property) function Total the value of the named property in all counters in the same stack as the specified piece.Convert a String value into a wrapped primitive object if possible.Methods inherited from class VASSAL.script.AbstractInterpreter
alert, findMap, getModuleProperty, globalHotKey, isAccessible, setModuleProperty, setVar, setVar, setVar, setVar, setVarMethods inherited from class bsh.Interpreter
debug, error, eval, eval, eval, eval, get, getClassManager, getErr, getIn, getInterface, getNameSpace, getOut, getParent, getShowResults, getSourceFileInfo, getStrictJava, invokeMain, main, pathToFile, print, println, redirectOutputToFile, run, set, set, set, set, set, set, setClassLoader, setConsole, setErr, setExitOnEOF, setNameSpace, setOut, setShowResults, setStrictJava, source, source, unset
-
Field Details
-
INIT_SCRIPT
- See Also:
- Constant Field Values
-
THIS
- See Also:
- Constant Field Values
-
SOURCE
- See Also:
- Constant Field Values
-
MAGIC1
- See Also:
- Constant Field Values
-
MAGIC2
- See Also:
- Constant Field Values
-
MAGIC3
- See Also:
- Constant Field Values
-
topLevelNameSpace
protected static bsh.NameSpace topLevelNameSpace -
expressionNameSpace
protected bsh.NameSpace expressionNameSpace -
expression
-
variables
-
stringVariables
-
source
-
-
Constructor Details
-
ExpressionInterpreter
Private constructor to build an ExpressionInterpreter. Interpreters can only be created by createInterpreter.- Parameters:
expr- Expression- Throws:
ExpressionException- Invalid Expression details
-
-
Method Details
-
getComponentTypeName
- Specified by:
getComponentTypeNamein interfaceRecursionLimiter.Loopable
-
getComponentName
- Specified by:
getComponentNamein interfaceRecursionLimiter.Loopable
-
strip
-
initialiseStatic
protected void initialiseStatic()Initialise the static elements of this class. Create a Top Level NameSpace using the Vassal class loader, load useful classes and read and process the init_expression.bsh file to load scripted methods available to expressions. -
getExpression
Return the current expression- Returns:
- expression
-
evaluate
Evaluate the expression, setting the value of any undefined values to the matching Vassal property value. Primitives must be wrapped.- Returns:
- result
- Throws:
ExpressionException
-
evaluate
- Throws:
ExpressionException
-
evaluate
- Throws:
ExpressionException
-
wrap
Convert a String value into a wrapped primitive object if possible. Note this is a non-static copy of BeanShell.wrap(). Callbacks from beanshell (e.g. getProperty) fail if an attempt is made to call a static method.- Parameters:
value- Value to wrap- Returns:
- wrapped value
-
getProperty
Callbacks from BeanShell Expressions to Vassal -
getLocalizedProperty
-
getZoneProperty
-
getZoneProperty
-
getMapProperty
-
sumStack
SumStack(property) function Total the value of the named property in all counters in the same stack as the specified piece.- Parameters:
property- Property Nameps- GamePiece- Returns:
- total
-
sumLocation
SumLocation(property) function Total the value of the named property in all counters in the same location as the specified piece.* WARNING * This WILL be inefficient as the number of counters on the map increases.
- Parameters:
property- Property Nameps- GamePiece- Returns:
- total
-
random
-
isRandom
-
sum
-
sum
-
count
-
count
-