Class ScriptEnvironment

java.lang.Object
com.blackrook.rookscript.ScriptEnvironment

public class ScriptEnvironment extends Object
A script environment accessor object. This manages references to the host, standard streams, and system/environment variables.
Author:
Matthew Tropiano
  • Method Details

    • create

      public static ScriptEnvironment create()
      Builds an environment link connected to nothing.
      Returns:
      a new script environment to bind to an instance.
    • create

      public static ScriptEnvironment create(Object hostInterface)
      Builds an environment link for just the host interface object.
      Parameters:
      hostInterface - the host interface object.
      Returns:
      a new script environment to bind to an instance.
    • create

      public static ScriptEnvironment create(PrintStream standardOut, PrintStream standardErr, InputStream standardIn)
      Builds an environment link for the standard I/O streams.
      Parameters:
      standardOut - the stream to use for the standard output stream.
      standardErr - the stream to use for the standard error stream.
      standardIn - the stream to use for the standard input stream.
      Returns:
      a new script environment to bind to an instance.
    • create

      public static ScriptEnvironment create(Object hostInterface, PrintStream standardOut, PrintStream standardErr, InputStream standardIn)
      Builds an environment link connected to a host and standard streams.
      Parameters:
      hostInterface - the host interface object.
      standardOut - the stream to use for the standard output stream.
      standardErr - the stream to use for the standard error stream.
      standardIn - the stream to use for the standard input stream.
      Returns:
      a new script environment to bind to an instance.
    • createStandardEnvironment

      public static ScriptEnvironment createStandardEnvironment()
      Builds an environment link for the standard I/O streams. All of standard streams are used for out, error, and in.
      Returns:
      a new script environment to bind to an instance.
      See Also:
    • createStandardEnvironment

      public static ScriptEnvironment createStandardEnvironment(Object hostInterface)
      Builds an environment link for the standard I/O streams and the host interface object. All of standard streams are used for out, error, and in.
      Parameters:
      hostInterface - the host interface object.
      Returns:
      a new script environment to bind to an instance.
      See Also:
    • getHostInterface

      public Object getHostInterface()
      Gets the host interface that this environment uses for host calls.
      Returns:
      the instance to use.
    • print

      public void print(Object object)
      Prints the string representation of an object to the standard out stream, if bound. If this is not bound to a standard out stream, this does nothing.
      Parameters:
      object - the object to print.
    • printErr

      public void printErr(Object object)
      Prints the string representation of an object to the standard error stream, if bound. If this is not bound to a standard error stream, this does nothing.
      Parameters:
      object - the object to print.
    • read

      public int read() throws IOException
      Reads from the standard in stream, if bound. If this is not bound to a standard input stream, this returns -1.
      Returns:
      the byte value read from input.
      Throws:
      IOException - if a read error occurs.
      See Also:
    • read

      public int read(byte[] buffer, int offset, int len) throws IOException
      Reads from the standard in stream into an array, if bound. If this is not bound to a standard input stream, this returns -1.
      Parameters:
      buffer - an array of bytes to write into.
      offset - the offset into the array to start the write.
      len - the maximum amount of bytes to read.
      Returns:
      the amount of bytes read from input.
      Throws:
      IOException - if a read error occurs.
      See Also:
    • getStandardIn

      public InputStream getStandardIn()
      Returns:
      the bound standard in stream.
    • getStandardOut

      public PrintStream getStandardOut()
      Returns:
      the bound standard out stream.
    • getStandardErr

      public PrintStream getStandardErr()
      Returns:
      the bound standard error stream.