Package com.blackrook.rookscript
Class ScriptInstanceBuilder
java.lang.Object
com.blackrook.rookscript.ScriptInstanceBuilder
A script instance builder for new script instances and such.
- Author:
- Matthew Tropiano
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionandFunctionResolver
(ScriptFunctionResolver resolver) Adds a function resolver to this builder to be used in the script.andFunctionResolver
(String namespace, ScriptFunctionResolver resolver) Adds a function resolver to this builder to be used in the script.andScope
(String name, ScriptVariableResolver resolver) Adds a scope to be used in the script.Creates the instance using the set components, then calls an entry point with a set of parameters.<T> T
callAndReturnAs
(Class<T> returnType, String entryName, Object... parameters) Creates the instance using the set components, then calls an entry point with a set of parameters.Gets the instance built from the set components.Gets the instance built from the set components.usingReaderIncluder
(ScriptReaderIncluder includer) Adds the optional reader includer to use for compiling code.usingReaderOptions
(ScriptReaderOptions options) Adds the optional reader options to use for compiling code.withEnvironment
(ScriptEnvironment environment) Sets the script environment for this script.withFunctionResolver
(ScriptFunctionResolver resolver) Adds a function resolver to this builder to be used in the script, clearing all resolvers first. Each instance created will use the resolvers added for compiling and runtime.withFunctionResolver
(String namespace, ScriptFunctionResolver resolver) Adds a function resolver to this builder to be used in the script, clearing all resolvers first. Each instance created will use the resolvers added for compiling and runtime.withRunawayLimit
(int runawayLimit) Sets the runaway limit for the instance.withScope
(String name, ScriptVariableResolver resolver) Adds a scope to be used in the script, clearing the set of scopes first.withScript
(Script script) Attaches the script used for this instance.withScriptStack
(int activationDepth, int valueStackDepth) Attaches a new script instance stack used for this instance.Attaches a script instance stack for this instance.withSource
(File sourceFile) Attaches script source to compile on instantiation.withSource
(String sourceData) Attaches script source to compile on instantiation.withSource
(String streamPath, InputStream sourceStream) Attaches script input stream source to compile on instantiation.withSource
(String streamPath, Reader sourceReader) Attaches script source to compile on instantiation.withSource
(String sourcePath, String sourceData) Attaches script source to compile on instantiation.withWaitHandler
(ScriptWaitHandler waitHandler) Sets the wait handler for the script instance.
-
Method Details
-
withSource
Attaches script source to compile on instantiation. Replaces an existing script source, if set before.- Parameters:
sourceData
- the source data.- Returns:
- the builder, for chained calls.
-
withSource
Attaches script source to compile on instantiation. Replaces an existing script source, if set before.- Parameters:
sourcePath
- the path name of this string data (for include path parent).sourceData
- the source data.- Returns:
- the builder, for chained calls.
-
withSource
Attaches script source to compile on instantiation. Replaces an existing script source, if set before.- Parameters:
sourceFile
- the source file.- Returns:
- the builder, for chained calls.
-
withSource
Attaches script input stream source to compile on instantiation. Replaces an existing script source, if set before.- Parameters:
streamPath
- the stream path (used for errors and include directives).sourceStream
- the source stream.- Returns:
- the builder, for chained calls.
-
withSource
Attaches script source to compile on instantiation. Replaces an existing script source, if set before.- Parameters:
streamPath
- the stream path (used for errors and include directives).sourceReader
- the source reader.- Returns:
- the builder, for chained calls.
-
usingReaderIncluder
Adds the optional reader includer to use for compiling code.- Parameters:
includer
- the reader includer to use.- Returns:
- the builder, for chained calls.
-
usingReaderOptions
Adds the optional reader options to use for compiling code.- Parameters:
options
- the reader options to use.- Returns:
- the builder, for chained calls.
-
withScript
Attaches the script used for this instance. Removes an existing script source, if set before.- Parameters:
script
- the script to use.- Returns:
- the builder, for chained calls.
-
withScriptStack
Attaches a new script instance stack used for this instance. Each instance created will create a new stack instance.- Parameters:
activationDepth
- the activation stack depth.valueStackDepth
- the value stack depth.- Returns:
- the builder, for chained calls.
-
withScriptStack
Attaches a script instance stack for this instance. Each instance created will reuse the provided stack instance.- Parameters:
stack
- the stack to use.- Returns:
- the builder, for chained calls.
-
withFunctionResolver
Adds a function resolver to this builder to be used in the script, clearing all resolvers first. Each instance created will use the resolvers added for compiling and runtime.- Parameters:
resolver
- the resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
withFunctionResolver
public ScriptInstanceBuilder withFunctionResolver(String namespace, ScriptFunctionResolver resolver) Adds a function resolver to this builder to be used in the script, clearing all resolvers first. Each instance created will use the resolvers added for compiling and runtime.- Parameters:
namespace
- the namespace to use for the resolver.resolver
- the resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
andFunctionResolver
Adds a function resolver to this builder to be used in the script. Each instance created will use the resolvers added for compiling and runtime.- Parameters:
resolver
- the resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
andFunctionResolver
Adds a function resolver to this builder to be used in the script. Each instance created will use the resolvers added for compiling and runtime.- Parameters:
namespace
- the namespace to use for the resolver.resolver
- the resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
withScope
Adds a scope to be used in the script, clearing the set of scopes first. Each instance created will be provided with the added scopes at runtime.- Parameters:
name
- the scope name.resolver
- the scope resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
andScope
Adds a scope to be used in the script. Each instance created will be provided with the added scopes at runtime.- Parameters:
name
- the scope name.resolver
- the scope resolver to add.- Returns:
- the builder, for chained calls.
- See Also:
-
withWaitHandler
Sets the wait handler for the script instance. Each instance created will use this wait handler when a script is forced into aScriptInstance.State.WAITING
state.- Parameters:
waitHandler
- the waiting handler to attach.- Returns:
- the builder, for chained calls.
- See Also:
-
withEnvironment
Sets the script environment for this script. Each instance created will use this environment.- Parameters:
environment
- the environment to use.- Returns:
- the builder, for chained calls.
-
withRunawayLimit
Sets the runaway limit for the instance. Each instance created will use this limit.- Parameters:
runawayLimit
- the limit. 0 or less is no limit.- Returns:
- the builder, for chained calls.
-
createInstance
Gets the instance built from the set components. The script is compiled through this call. Any parsing errors are thrown as ScriptBuilderException with the parser error as the cause.- Returns:
- a new ScriptInstance created from the characteristics set.
- Throws:
ScriptInstanceBuilder.BuilderException
- if the instance can't be built.
-
createFactory
Gets the instance built from the set components. The script is compiled through this call. Any parsing errors are thrown as ScriptBuilderException with the parser error as the cause.- Returns:
- a new ScriptInstance created from the characteristics set.
- Throws:
ScriptInstanceBuilder.BuilderException
- if the instance can't be built.
-
call
Creates the instance using the set components, then calls an entry point with a set of parameters. The script is compiled through this call. Any parsing errors are thrown as ScriptBuilderException with the parser error as the cause.- Parameters:
entryName
- the entry point name.parameters
- the starting parameters to push onto the stack.- Returns:
- a new ScriptInstance created from the characteristics set.
- Throws:
ScriptInstanceBuilder.BuilderException
- if the instance can't be built.ScriptExecutionException
- if the provided amount of parameters do not match the amount of parameters that the script requires, or the provided entry point does not exist.- See Also:
-
callAndReturnAs
Creates the instance using the set components, then calls an entry point with a set of parameters. The script is compiled through this call. Any parsing errors are thrown as ScriptBuilderException with the parser error as the cause.The script instance is lost from this call - only use this if you want to execute and discard the execution instance.
- Type Parameters:
T
- the return type.- Parameters:
returnType
- the return type to get from the script.entryName
- the entry point name.parameters
- the starting parameters to push onto the stack.- Returns:
- a new ScriptInstance created from the characteristics set.
- Throws:
ScriptInstanceBuilder.BuilderException
- if the instance can't be built.ScriptExecutionException
- if the provided amount of parameters do not match the amount of parameters that the script requires, or the provided entry point does not exist.- See Also:
-