如何从 scala 程序调用 scala REPL 控制台?
how to call scala REPL console from scala program?
我需要在我的 Scala 应用程序中嵌入 Scala REPL 功能。我怎样才能做到这一点 ?我需要调用哪个 Scala method/class?
我查看了 scala.tools.nsc.interpreter 包,但我不知道该怎么做。
@som-snytt 给了我一个提示,我得到了解决方案。
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
}
我需要在我的 Scala 应用程序中嵌入 Scala REPL 功能。我怎样才能做到这一点 ?我需要调用哪个 Scala method/class?
我查看了 scala.tools.nsc.interpreter 包,但我不知道该怎么做。
@som-snytt 给了我一个提示,我得到了解决方案。
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
}