-
-
Save andyscott/906237 to your computer and use it in GitHub Desktop.
Scala Drop to REPL (like debug break..)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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