Package VASSAL.script
Class ExpressionInterpreter
java.lang.Object
bsh.Interpreter
VASSAL.script.AbstractInterpreter
VASSAL.script.ExpressionInterpreter
- All Implemented Interfaces:
bsh.ConsoleInterface
,Serializable
,Runnable
,Auditable
,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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected String
protected bsh.NameSpace
protected static final String
protected static final String
protected static final String
protected static final String
protected PropertySource
protected static final String
protected static final String
protected static bsh.NameSpace
Fields inherited from class VASSAL.script.AbstractInterpreter
myNameSpace
Fields 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 TypeMethodDescriptioncountStack
(String property, PropertySource ps) CountStack(property) function count the number of pieces in the same stack which have any non-blank value for the specified property.evaluate()
Evaluate the expression, setting the value of any undefined values to the matching Vassal property value.evaluate
(PropertySource ps, boolean localized) evaluate
(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit) evaluate
(PropertySource ps, Map<String, String> properties, boolean localized, Auditable owner, AuditTrail audit) Return the name of the trait or Component an Auditable isReturn a description of the Type of trait or Component an Auditable isReturn the current expressiongetLocalizedProperty
(String name) getMapProperty
(String propertyName, String mapName) getProperty
(String name) Callbacks from BeanShell Expressions to VassalgetProperty minus the wrapgetZoneProperty
(String propertyName, String zoneName) getZoneProperty
(String propertyName, String zoneName, String mapName) protected void
Initialise the static elements of this class.protected static String
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.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, 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:
-
THIS
- See Also:
-
SOURCE
- See Also:
-
MAGIC1
- See Also:
-
MAGIC2
- See Also:
-
MAGIC3
- See Also:
-
ERROR_PREFIX
- See Also:
-
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
Description copied from interface:Auditable
Return a description of the Type of trait or Component an Auditable is- Specified by:
getComponentTypeName
in interfaceAuditable
- Returns:
- Component Type
-
getComponentName
Description copied from interface:Auditable
Return the name of the trait or Component an Auditable is- Specified by:
getComponentName
in interfaceAuditable
- Returns:
- Component name
-
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
public String evaluate(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit) throws ExpressionException - Throws:
ExpressionException
-
evaluate
public String evaluate(PropertySource ps, Map<String, String> properties, boolean localized, Auditable owner, AuditTrail audit) throws ExpressionException- 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
-
getString
getProperty minus the wrap -
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
-
countStack
CountStack(property) function count the number of pieces in the same stack which have any non-blank value for the specified property.- 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
-