Skip to content

Instantly share code, notes, and snippets.

@andyscott
Forked from retronym/drop-to-repl-2.8.scala
Created April 6, 2011 18:39
Show Gist options
  • Save andyscott/906237 to your computer and use it in GitHub Desktop.
Save andyscott/906237 to your computer and use it in GitHub Desktop.
Scala Drop to REPL (like debug break..)
/**
* Originally authored by Jason. Updated by me (Andy) to work in Scala 2.9 RC1
*
* @author Jason Zaugg (aka retronym), Andy Scott
*/
object InterpreterUtil {
import scala.tools.nsc.interpreter._
import scala.tools.nsc.interpreter.Results._
import scala.tools.nsc.Settings
def createREPL(args: NamedParam*): ILoop = {
val intLoop = new ILoop
intLoop.settings = {
val s = new Settings(println)
s.embeddedDefaults(getClass.getClassLoader)
s.classpath.value = System.getProperty("java.class.path")
s
}
intLoop.createInterpreter
intLoop.in = InteractiveReader()
intLoop.intp.initialize
// rebind exit so people don't accidentally call System.exit by way of predef
intLoop.intp.beQuietDuring {
intLoop.intp.interpret("""def exit = println("Type :quit to resume program execution.")""")
for (p <- args) {
intLoop.intp.bind(p) match {
case Results.Error =>
case _ => println(p.toString)
}
}
}
intLoop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment