Ejemplo n.º 1
0
 /** Transfers variables from one interpreter's bindings to another. */
 private void copyBindings(final ScriptInterpreter src, final ScriptInterpreter dest) {
   if (src == null) return; // nothing to copy
   final Bindings srcBindings = src.getBindings();
   final Bindings destBindings = dest.getBindings();
   for (final String key : src.getBindings().keySet()) {
     final Object value = src.getLanguage().decode(srcBindings.get(key));
     destBindings.put(key, value);
   }
 }
Ejemplo n.º 2
0
  /** Lists variables in the script context. */
  public void vars() {
    if (interpreter == null) return; // no active script language

    final List<String> keys = new ArrayList<>();
    final List<Object> types = new ArrayList<>();
    final Bindings bindings = interpreter.getBindings();
    for (final String key : bindings.keySet()) {
      final Object value = bindings.get(key);
      keys.add(key);
      types.add(type(value));
    }
    printColumns(keys, types);
  }
Ejemplo n.º 3
0
 /** Outputs a greeting, and sets up the initial language of the REPL. */
 public void initialize() {
   out.println("Welcome to the SciJava REPL!");
   out.println();
   help();
   final List<ScriptLanguage> langs = getInterpretedLanguages();
   if (langs.isEmpty()) {
     out.println("--------------------------------------------------------------");
     out.println("Uh oh! There are no SciJava script languages available!");
     out.println("Are any on your classpath? E.g.: org.scijava:scripting-groovy?");
     out.println("--------------------------------------------------------------");
     out.println();
     return;
   }
   out.println("Have fun!");
   out.println();
   lang(langs.get(0).getLanguageName());
   populateBindings(interpreter.getBindings());
 }