sleep.interfaces
Interface Operator


public interface Operator

An operator in sleep parlance is anything used to operate on two variables inside of an expression. For example 2 + 3 is the expression add 2 and 3. The + plus sign is the operator.

Creating an Operator class and installing it into the environment makes the operator available for use within expressions.

To install an operator into a script environment:

 ScriptInstance script;           // assume
 Operator       myOperatorBridge; // assume
 
 Hashtable environment = script.getScriptEnvironment().getEnvironment();
 environment.put("operator", myOperatorBridge);
 

Operator bridges probably won't be as common as other bridges. Operator bridges can be used for adding new math operators or new string manipulation operators.


Method Summary
 Scalar operate(java.lang.String operatorName, ScriptInstance anInstance, java.util.Stack passedInLocals)
          apply operator operatorName on the values in the stack.
 

Method Detail

operate

Scalar operate(java.lang.String operatorName,
               ScriptInstance anInstance,
               java.util.Stack passedInLocals)
apply operator operatorName on the values in the stack.

Parameters:
operatorName - the name of the operator, for example the String "+"
anInstance - instance of the script calling this operator
passedInLocals - a stack containing values the operator is to be applied to: [left hand side, right hand side]
Returns:
a Scalar containing the result of the operatorName applied to the passedInLocals, in the case of "+" applied to [4, 3] we would get a Scalar containing the integer 7.