Package org.scijava.script
Class ScriptREPL
- java.lang.Object
-
- org.scijava.script.ScriptREPL
-
public class ScriptREPL extends Object
A REPL for SciJava script engines, which allows dynamic language switching.- Author:
- Curtis Rueden
-
-
Constructor Summary
Constructors Constructor Description ScriptREPL(Context context)ScriptREPL(Context context, OutputStream out)ScriptREPL(Context context, String language)ScriptREPL(Context context, String language, OutputStream out)ScriptREPL(Context context, String language, Consumer<String> out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug()booleanevaluate(String line)Evaluates the line, including handling of special colon-prefixed REPL commands.List<ScriptLanguage>getInterpretedLanguages()Gets the list of languages compatible with the REPL.ScriptInterpretergetInterpreter()Gets the script interpreter for the currently active language.voidhelp()Prints a usage guide.voidinitialize()Outputs a greeting, and sets up the initial language and variables of the REPL.voidinitialize(boolean verbose)Sets up the initial language and variables of the REPL.voidlang(String langName)Creates a newScriptInterpreterto interpret statements, preserving existing variables from the previous interpreter.voidlang(ScriptLanguage language)Creates a newScriptInterpreterto interpret statements, preserving existing variables from the previous interpreter.voidlangs()voidloop()Starts a Read-Eval-Print-Loop from the standard input stream, returning when the loop terminates.voidloop(InputStream in)Starts a Read-Eval-Print-Loop from the given input stream, returning when the loop terminates.voidloop(Supplier<?> in)Starts a Read-Eval-Print-Loop from the given source, returning when the loop terminates.static voidmain(String... args)voidprompt()Outputs the prompt.voidvars()Lists variables in the script context.
-
-
-
Constructor Detail
-
ScriptREPL
public ScriptREPL(Context context)
-
ScriptREPL
public ScriptREPL(Context context, OutputStream out)
-
ScriptREPL
public ScriptREPL(Context context, String language, OutputStream out)
-
-
Method Detail
-
getInterpretedLanguages
public List<ScriptLanguage> getInterpretedLanguages()
Gets the list of languages compatible with the REPL.This list will match those given by
ScriptService.getLanguages(), but filtered to exclude any who reporttrueforScriptLanguage.isCompiledLanguage().
-
getInterpreter
public ScriptInterpreter getInterpreter()
Gets the script interpreter for the currently active language.
-
loop
public void loop() throws IOExceptionStarts a Read-Eval-Print-Loop from the standard input stream, returning when the loop terminates.- Throws:
IOException
-
loop
public void loop(InputStream in) throws IOException
Starts a Read-Eval-Print-Loop from the given input stream, returning when the loop terminates.- Parameters:
in- Input stream from which commands are read.- Throws:
IOException
-
loop
public void loop(Supplier<?> in)
Starts a Read-Eval-Print-Loop from the given source, returning when the loop terminates.- Parameters:
in- Source from which commands are read.
-
initialize
public void initialize()
Outputs a greeting, and sets up the initial language and variables of the REPL.
-
initialize
public void initialize(boolean verbose)
Sets up the initial language and variables of the REPL.- Parameters:
verbose- Whether to output an initial greeting.
-
prompt
public void prompt()
Outputs the prompt.
-
evaluate
public boolean evaluate(String line)
Evaluates the line, including handling of special colon-prefixed REPL commands.- Parameters:
line- The line to evaluate.- Returns:
- False iff the REPL should exit.
-
help
public void help()
Prints a usage guide.
-
vars
public void vars()
Lists variables in the script context.
-
lang
public void lang(String langName)
Creates a newScriptInterpreterto interpret statements, preserving existing variables from the previous interpreter.- Parameters:
langName- The script language of the new interpreter.- Throws:
IllegalArgumentException- if the requested language is not available.
-
lang
public void lang(ScriptLanguage language)
Creates a newScriptInterpreterto interpret statements, preserving existing variables from the previous interpreter.- Parameters:
language- The script language of the new interpreter.
-
langs
public void langs()
-
debug
public void debug()
-
-