Class Script

java.lang.Object
com.blackrook.rookscript.Script

public class Script extends Object
A compiled script.
Author:
Matthew Tropiano
  • Field Details

  • Constructor Details

    • Script

      public Script()
      Creates a new empty script.
  • Method Details

    • setHostFunctionResolver

      public void setHostFunctionResolver(ScriptHostFunctionResolver hostFunctionResolver)
      Sets this script's host function resolver.
      Parameters:
      hostFunctionResolver - the function resolver.
      Throws:
      NullPointerException - if hostFunctionResolver is null.
    • setScopeResolver

      public void setScopeResolver(ScriptScopeResolver scopeResolver)
      Sets this script's scope resolver.
      Parameters:
      scopeResolver - the scope resolver.
      Throws:
      NullPointerException - if scopeResolver is null.
    • setCommands

      public void setCommands(ScriptCommand[] commands)
      Sets the commands to use in the script, replacing them entirely.
      Parameters:
      commands - the new command set.
    • createFunctionEntry

      public Script.Entry createFunctionEntry(String name, int parameterCount, int index)
      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

      public Script.Entry getFunctionEntry(String name)
      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

      public void setScriptEntry(String name, int parameterCount, int index)
      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

      public Script.Entry getScriptEntry(String name)
      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

      public String[] getScriptEntryNames()
      Returns:
      an array of this script's entry point names.
      Since:
      1.13.0
    • setIndex

      public void setIndex(String label, int index)
      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

      public int getIndex(String label)
      Gets the corresponding index for a label.
      Parameters:
      label - the label to look up.
      Returns:
      the corresponding index or -1 if not found.
    • getHostFunctionResolver

      public ScriptHostFunctionResolver getHostFunctionResolver()
      Returns this script's host function resolver.
      Returns:
      the function resolver.
    • getScopeResolver

      public ScriptScopeResolver getScopeResolver()
      Returns this script's scope resolver.
      Returns:
      the scope resolver.
    • getCommand

      public ScriptCommand getCommand(int index)
      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

      public void addCommand(ScriptCommand command)
      Adds a command directive to the script. Be very careful with this!
      Parameters:
      command - the command to add.
    • getNextGeneratedLabel

      public String getNextGeneratedLabel(String prefix)
      Generates the next label for a specific label prefix.
      Parameters:
      prefix - the label prefix.
      Returns:
      a new label to use.
    • getNextGeneratedLabelNumber

      public int getNextGeneratedLabelNumber(String prefix)
      Returns the current generated label counter for a specific label prefix.
      Parameters:
      prefix - the label prefix.
      Returns:
      the current counter value.
    • getLabelsAtIndex

      public Iterable<String> getLabelsAtIndex(int index)
      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.