rlgamekit.interpreter
Class Interpreter

java.lang.Object
  extended by rlgamekit.interpreter.Interpreter

public class Interpreter
extends java.lang.Object

A (slow) interpreter framework for an extensible scripting language. All functions of the language and all details of the language must be implemented in the Functions class or a subclass of it. This is neither complete nor stable and only provided as a preview of a possible scripting interpreter to be part of the roguelike game kit. The goal is to have a very simple languge of lines like command arguments - the commands must match method names in the Functions class, and the arguments are interpreted by the functions themselves. A Tokenizer class is provided to split the arguments into more meaningful Tokens.

See Also:
Functions, Tokenizer, Token

Constructor Summary
Interpreter()
          Create a new interpreter.
 
Method Summary
 void runCommand(int lineNumber, java.lang.String call, java.lang.String argument)
          Run a command from a script line.
 void runLine(int lineNumber, java.lang.String line)
          Interpret (run) a single line from a script.
 void runScript(java.util.List<java.lang.String> script)
          Interpret (run) a script.
 void runScript(java.lang.String[] script)
          Interpret (run) a script.
 void setFunctions(Functions functions)
          Set user defined functions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter()
Create a new interpreter.

Method Detail

setFunctions

public void setFunctions(Functions functions)
Set user defined functions.

Parameters:
functions -

runScript

public void runScript(java.lang.String[] script)
Interpret (run) a script.

Parameters:
script - All lines of the script

runScript

public void runScript(java.util.List<java.lang.String> script)
Interpret (run) a script.

Parameters:
script - All lines of the script

runLine

public void runLine(int lineNumber,
                    java.lang.String line)
Interpret (run) a single line from a script.

Parameters:
lineNumber - the line number
line - the script code line

runCommand

public void runCommand(int lineNumber,
                       java.lang.String call,
                       java.lang.String argument)
Run a command from a script line.

Parameters:
lineNumber - the number of the line in the script. Only used for reporting errors, can be set to any number if executing single commands.
call - the command name
argument - the arguments of the command as string