0

I need embed Scala REPL functionality in my Scala Application. How can I do that ? Which Scala method/class I need to call ?

I take a look at scala.tools.nsc.interpreter package but I don't see how to do that.

João Paraná
  • 1,031
  • 1
  • 9
  • 18
  • 1
    ILoop is the REPL, `process(settings)` is entry point. IMain is the interpreter per se, `interpret(line)` is entry point. There's also separate `javax.script` usage, `Scripted` in 2.12. The Ammonite REPL may offer better embedding experience. – som-snytt Mar 02 '17 at 16:58

1 Answers1

0

@som-snytt gave me a tip and I got the solution.

import scala.tools.nsc.interpreter._

val lines: List[String] = List("println(\"Hello\")", "println(\"Word\")")
val ret: String = ILoop.run(lines)
// Verify if all runs OK

// Read stdin
val condition = ...
while (condition) {
  // convert to List[String] 
  val ret: String = ILoop.run(lines)
  // format and print the output
  println(ret)
  // Read stdin again
}
João Paraná
  • 1,031
  • 1
  • 9
  • 18