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
public class ExpressionInterpreter extends AbstractInterpreter implements 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
Fields Modifier and Type Field Description protected static HashMap<String,ExpressionInterpreter>cacheprotected Stringexpressionprotected bsh.NameSpaceexpressionNameSpaceprotected static StringINIT_SCRIPTprotected static StringMAGIC1protected static StringMAGIC2protected static StringMAGIC3protected PropertySourcesourceprotected static StringSOURCEprotected List<String>stringVariablesprotected static StringTHISprotected static bsh.NameSpacetopLevelNameSpaceprotected List<String>variablesFields inherited from class VASSAL.script.AbstractInterpreter
myNameSpaceFields inherited from class bsh.Interpreter
DEBUG, evalOnly, interactive, LOCALSCOPING, TRACE, VERSION -
Method Summary
Modifier and Type Method Description Objectcount(Object source, Object propertyMatch)Objectcount(Object source, Object propertyMatch, Object mapName)static ExpressionInterpretercreateInterpreter(String expr)Stringevaluate()Stringevaluate(PropertySource ps)Evaluate the expression, setting the value of any undefined values to the matching Vassal property value.Stringevaluate(PropertySource ps, boolean localized)StringgetComponentName()StringgetComponentTypeName()StringgetExpression()Return the current expressionObjectgetLocalizedProperty(String name)ObjectgetMapProperty(String propertyName, String mapName)ObjectgetProperty(String name)Callbacks from BeanShell Expressions to VassalObjectgetZoneProperty(String propertyName, String zoneName)ObjectgetZoneProperty(String propertyName, String zoneName, String mapName)protected voidinitialiseStatic()Initialise the static elements of this class.ObjectisRandom(Object source, Object percentString)Objectrandom(Object source, Object minString, Object maxString)protected static Stringstrip(String expr)Objectsum(Object source, Object propertyName, Object propertyMatch)Objectsum(Object source, Object propertyName, Object propertyMatch, Object mapName)ObjectsumLocation(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.ObjectsumStack(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.Objectwrap(String value)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
-
source
-
variables
-
stringVariables
-
cache
-
-
Method Details
-
getComponentTypeName
- Specified by:
getComponentTypeNamein interfaceRecursionLimiter.Loopable
-
getComponentName
- Specified by:
getComponentNamein interfaceRecursionLimiter.Loopable
-
createInterpreter
- Throws:
ExpressionException
-
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
-