[英]how to call scala REPL console from scala program?
我需要在我的Scala應用程序中嵌入Scala REPL功能。 我怎樣才能做到這一點 ? 我需要調用哪個Scala方法/類?
我看一下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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.