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>
cache
protected String
expression
protected bsh.NameSpace
expressionNameSpace
protected static String
INIT_SCRIPT
protected static String
MAGIC1
protected static String
MAGIC2
protected static String
MAGIC3
protected PropertySource
source
protected static String
SOURCE
protected List<String>
stringVariables
protected static String
THIS
protected static bsh.NameSpace
topLevelNameSpace
protected List<String>
variables
Fields inherited from class VASSAL.script.AbstractInterpreter
myNameSpace
Fields inherited from class bsh.Interpreter
DEBUG, evalOnly, interactive, LOCALSCOPING, TRACE, VERSION
-
Method Summary
Modifier and Type Method Description Object
count(Object source, Object propertyMatch)
Object
count(Object source, Object propertyMatch, Object mapName)
static ExpressionInterpreter
createInterpreter(String expr)
String
evaluate()
String
evaluate(PropertySource ps)
Evaluate the expression, setting the value of any undefined values to the matching Vassal property value.String
evaluate(PropertySource ps, boolean localized)
String
getComponentName()
String
getComponentTypeName()
String
getExpression()
Return the current expressionObject
getLocalizedProperty(String name)
Object
getMapProperty(String propertyName, String mapName)
Object
getProperty(String name)
Callbacks from BeanShell Expressions to VassalObject
getZoneProperty(String propertyName, String zoneName)
Object
getZoneProperty(String propertyName, String zoneName, String mapName)
protected void
initialiseStatic()
Initialise the static elements of this class.Object
isRandom(Object source, Object percentString)
Object
random(Object source, Object minString, Object maxString)
protected static String
strip(String expr)
Object
sum(Object source, Object propertyName, Object propertyMatch)
Object
sum(Object source, Object propertyName, Object propertyMatch, Object mapName)
Object
sumLocation(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.Object
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.Object
wrap(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, setVar
Methods 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:
getComponentTypeName
in interfaceRecursionLimiter.Loopable
-
getComponentName
- Specified by:
getComponentName
in 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
-