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 Details

  • Constructor Details

    • ExpressionInterpreter

      public ExpressionInterpreter(String expr) throws ExpressionException
      Private constructor to build an ExpressionInterpreter. Interpreters can only be created by createInterpreter.
      Parameters:
      expr - Expression
      Throws:
      ExpressionException - Invalid Expression details
  • Method Details

    • getComponentTypeName

      public String getComponentTypeName()
      Specified by:
      getComponentTypeName in interface RecursionLimiter.Loopable
    • getComponentName

      public String getComponentName()
      Specified by:
      getComponentName in interface RecursionLimiter.Loopable
    • strip

      protected static String strip(String expr)
    • 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

      public String getExpression()
      Return the current expression
      Returns:
      expression
    • evaluate

      public String evaluate(PropertySource ps) throws ExpressionException
      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

      public String evaluate(PropertySource ps, boolean localized) throws ExpressionException
      Throws:
      ExpressionException
    • evaluate

      public String evaluate() throws ExpressionException
      Throws:
      ExpressionException
    • wrap

      public Object wrap(String value)
      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

      public Object getProperty(String name)
      Callbacks from BeanShell Expressions to Vassal
    • getLocalizedProperty

      public Object getLocalizedProperty(String name)
    • getZoneProperty

      public Object getZoneProperty(String propertyName, String zoneName)
    • getZoneProperty

      public Object getZoneProperty(String propertyName, String zoneName, String mapName)
    • getMapProperty

      public Object getMapProperty(String propertyName, String mapName)
    • sumStack

      public 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.
      Parameters:
      property - Property Name
      ps - GamePiece
      Returns:
      total
    • sumLocation

      public 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.

      * WARNING * This WILL be inefficient as the number of counters on the map increases.

      Parameters:
      property - Property Name
      ps - GamePiece
      Returns:
      total
    • random

      public Object random(Object src, Object minString, Object maxString)
    • isRandom

      public Object isRandom(Object src, Object percentString)
    • sum

      public Object sum(Object src, Object propertyName, Object propertyMatch)
    • sum

      public Object sum(Object src, Object propertyName, Object propertyMatch, Object mapName)
    • count

      public Object count(Object src, Object propertyMatch)
    • count

      public Object count(Object src, Object propertyMatch, Object mapName)