Package com.blackrook.rookscript
Class Script
java.lang.Object
com.blackrook.rookscript.Script
A compiled script.
- Author:
- Matthew Tropiano
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommand
(ScriptCommand command) Adds a command directive to the script.createFunctionEntry
(String name, int parameterCount, int index) Creates/sets a command index for a function entry name in the script.getCommand
(int index) Gets the command at a specific index in the script.int
Gets the amount of commands in this script.getFunctionEntry
(String name) Gets the corresponding index for a subscript function name.Returns this script's host function resolver.int
Gets the corresponding index for a label.getLabelsAtIndex
(int index) Returns the list of labels at an index.getNextGeneratedLabel
(String prefix) Generates the next label for a specific label prefix.int
getNextGeneratedLabelNumber
(String prefix) Returns the current generated label counter for a specific label prefix.Returns this script's scope resolver.getScriptEntry
(String name) Gets the corresponding index for a subscript entry name.String[]
void
setCommands
(ScriptCommand[] commands) Sets the commands to use in the script, replacing them entirely.void
setHostFunctionResolver
(ScriptHostFunctionResolver hostFunctionResolver) Sets this script's host function resolver.void
Sets an index for a label in the script.void
setScopeResolver
(ScriptScopeResolver scopeResolver) Sets this script's scope resolver.void
setScriptEntry
(String name, int parameterCount, int index) Sets an index for a subscript entry name in the script.
-
Field Details
-
LABEL_FUNCTION_PREFIX
Function label prefix.- See Also:
-
LABEL_ENTRY_PREFIX
Script label prefix.- See Also:
-
-
Constructor Details
-
Script
public Script()Creates a new empty script.
-
-
Method Details
-
setHostFunctionResolver
Sets this script's host function resolver.- Parameters:
hostFunctionResolver
- the function resolver.- Throws:
NullPointerException
- if hostFunctionResolver is null.
-
setScopeResolver
Sets this script's scope resolver.- Parameters:
scopeResolver
- the scope resolver.- Throws:
NullPointerException
- if scopeResolver is null.
-
setCommands
Sets the commands to use in the script, replacing them entirely.- Parameters:
commands
- the new command set.
-
createFunctionEntry
Creates/sets a command index for a function entry name in the script. Also sets the function label index.NOTE: Function entry names are case-insensitive, but the label that they convert to are not. Those labels are converted to lower-case, and prefixed with "function_".
- Parameters:
name
- the name.parameterCount
- the amount of parameters that this takes.index
- the corresponding index.- Returns:
- the entry created as a result of the set.
-
getFunctionEntry
Gets the corresponding index for a subscript function name. Entry names are case-insensitive.- Parameters:
name
- the name to look up.- Returns:
- the corresponding index or -1 if not found.
-
setScriptEntry
Sets an index for a subscript entry name in the script. Also sets the entry label index.NOTE: Script entry names are case-insensitive, but the label that they convert to are not. Those labels are converted to lower-case, and prefixed with "entry_".
- Parameters:
name
- the name.parameterCount
- the amount of parameters that this takes.index
- the corresponding index.- See Also:
-
getScriptEntry
Gets the corresponding index for a subscript entry name. Entry names are case-insensitive.- Parameters:
name
- the name to look up.- Returns:
- the corresponding entry or null if not found.
-
getScriptEntryNames
- Returns:
- an array of this script's entry point names.
- Since:
- 1.13.0
-
setIndex
Sets an index for a label in the script. The label is used case-sensitively! Use caution when setting it!- Parameters:
label
- the label name.index
- the corresponding index.
-
getIndex
Gets the corresponding index for a label.- Parameters:
label
- the label to look up.- Returns:
- the corresponding index or -1 if not found.
-
getHostFunctionResolver
Returns this script's host function resolver.- Returns:
- the function resolver.
-
getScopeResolver
Returns this script's scope resolver.- Returns:
- the scope resolver.
-
getCommand
Gets the command at a specific index in the script.- Parameters:
index
- the index of the command.- Returns:
- the corresponding command, or null if out of range.
-
getCommandCount
public int getCommandCount()Gets the amount of commands in this script.- Returns:
- the amount of commands.
-
addCommand
Adds a command directive to the script. Be very careful with this!- Parameters:
command
- the command to add.
-
getNextGeneratedLabel
Generates the next label for a specific label prefix.- Parameters:
prefix
- the label prefix.- Returns:
- a new label to use.
-
getNextGeneratedLabelNumber
Returns the current generated label counter for a specific label prefix.- Parameters:
prefix
- the label prefix.- Returns:
- the current counter value.
-
getLabelsAtIndex
Returns the list of labels at an index. Creates a reverse lookup if this is the first time called.- Parameters:
index
- the index to look up.- Returns:
- an iterable structure with labels, or null for no labels.
-