Package com.blackrook.rookscript
Class ScriptEnvironment
java.lang.Object
com.blackrook.rookscript.ScriptEnvironment
A script environment accessor object.
This manages references to the host, standard streams, and system/environment variables.
- Author:
- Matthew Tropiano
-
Method Summary
Modifier and TypeMethodDescriptionstatic ScriptEnvironment
create()
Builds an environment link connected to nothing.static ScriptEnvironment
create
(PrintStream standardOut, PrintStream standardErr, InputStream standardIn) Builds an environment link for the standard I/O streams.static ScriptEnvironment
Builds an environment link for just the host interface object.static ScriptEnvironment
create
(Object hostInterface, PrintStream standardOut, PrintStream standardErr, InputStream standardIn) Builds an environment link connected to a host and standard streams.static ScriptEnvironment
Builds an environment link for the standard I/O streams.static ScriptEnvironment
createStandardEnvironment
(Object hostInterface) Builds an environment link for the standard I/O streams and the host interface object.Gets the host interface that this environment uses for host calls.void
Prints the string representation of an object to the standard out stream, if bound.void
Prints the string representation of an object to the standard error stream, if bound.int
read()
Reads from the standard in stream, if bound.int
read
(byte[] buffer, int offset, int len) Reads from the standard in stream into an array, if bound.
-
Method Details
-
create
Builds an environment link connected to nothing.- Returns:
- a new script environment to bind to an instance.
-
create
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
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
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
Gets the host interface that this environment uses for host calls.- Returns:
- the instance to use.
-
print
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
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
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
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
- Returns:
- the bound standard in stream.
-
getStandardOut
- Returns:
- the bound standard out stream.
-
getStandardErr
- Returns:
- the bound standard error stream.
-