sleep.bridges
Class SleepClosure

java.lang.Object
  extended by sleep.bridges.SleepClosure
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, Function

public class SleepClosure
extends java.lang.Object
implements Function, java.lang.Runnable

The Sleep Closure class. This class represents a Function object that is also a self contained closure

See Also:
Serialized Form

Constructor Summary
SleepClosure(ScriptInstance si, Block _code)
          Creates a new Sleep Closure, with a brand new set of internal variables.
SleepClosure(ScriptInstance si, Block _code, Variable _var)
          Creates a new Sleep Closure that uses the specified variable container for its internal variables
 
Method Summary
 Scalar callClosure(java.lang.String message, ScriptInstance si, java.util.Stack locals)
          "Safely" calls this closure.
 Scalar evaluate(java.lang.String message, ScriptInstance si, java.util.Stack locals)
          Evaluates the closure, use callClosure instead.
 java.lang.Object getAndRemoveMetadata(java.lang.Object key, java.lang.Object defaultv)
          obtain a key from the metadata store associated with this closure
 ScriptInstance getOwner()
          Returns the owning script instance
 Block getRunnableCode()
          Returns the runnable block of code associated with this closure
 Variable getVariables()
          Returns the variable container for this closures
 void putMetadata(java.lang.Object key, java.lang.Object value)
          put some value into the metadata store associated with this closure.
 void run()
          "Safely" calls this closure.
 java.util.Iterator scalarIterator()
           
 void setVariables(Variable _variables)
          Sets the variable environment for this closure
 java.lang.String toString()
          Information about this closure in the form of &closure[:]#
 java.lang.String toStringGeneric()
          Returns a generic string version of this closure without id information
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SleepClosure

public SleepClosure(ScriptInstance si,
                    Block _code)
Creates a new Sleep Closure, with a brand new set of internal variables. Don't be afraid, you can call this constructor from your code.


SleepClosure

public SleepClosure(ScriptInstance si,
                    Block _code,
                    Variable _var)
Creates a new Sleep Closure that uses the specified variable container for its internal variables

Method Detail

scalarIterator

public java.util.Iterator scalarIterator()

putMetadata

public void putMetadata(java.lang.Object key,
                        java.lang.Object value)
put some value into the metadata store associated with this closure.


getAndRemoveMetadata

public java.lang.Object getAndRemoveMetadata(java.lang.Object key,
                                             java.lang.Object defaultv)
obtain a key from the metadata store associated with this closure


toStringGeneric

public java.lang.String toStringGeneric()
Returns a generic string version of this closure without id information


toString

public java.lang.String toString()
Information about this closure in the form of &closure[:]#

Overrides:
toString in class java.lang.Object

getOwner

public ScriptInstance getOwner()
Returns the owning script instance


getRunnableCode

public Block getRunnableCode()
Returns the runnable block of code associated with this closure


getVariables

public Variable getVariables()
Returns the variable container for this closures


setVariables

public void setVariables(Variable _variables)
Sets the variable environment for this closure


run

public void run()
"Safely" calls this closure.

Specified by:
run in interface java.lang.Runnable

callClosure

public Scalar callClosure(java.lang.String message,
                          ScriptInstance si,
                          java.util.Stack locals)
"Safely" calls this closure. Use this if you are evaluating this closure from your own code.

Parameters:
message - the message to pass to this closure (available as $0)
the - calling script instance (null value assumes same as owner)
the - local data as a stack object (available as $1 .. $n)
Returns:
the scalar returned by this closure

evaluate

public Scalar evaluate(java.lang.String message,
                       ScriptInstance si,
                       java.util.Stack locals)
Evaluates the closure, use callClosure instead.

Specified by:
evaluate in interface Function
Parameters:
message - the function being called.
si - an instance of the script calling this function.
locals - a stack containing the locals passed to this function. The locals are Scalar values passed in reverse order i.e. [arg n, arg n-1, ..., arg 1, arg 0]
Returns:
an instance of Scalar containing the return value of this function.
See Also:
SleepUtils.runCode(Function, String, ScriptInstance, Stack)