Skip to content

Instantly share code, notes, and snippets.

@retronym
Created January 30, 2010 17:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save retronym/290632 to your computer and use it in GitHub Desktop.
Save retronym/290632 to your computer and use it in GitHub Desktop.
Embedding REPL in 2.8 working around classpath propagation changes.
object IntepreterFix {
import scala.tools.nsc._
import Interpreter._
def break(args: DebugParam[_]*): Unit = {
val intLoop = new InterpreterLoop
intLoop.settings = {
val s = new Settings(Console.println)
// need to pass this explicitly to the settings for Scalac.
// See: http://old.nabble.com/-scala--recent-changes-in-2.8-nightly-classpath-management-td26233977.html
s.classpath.value = System.getProperty("java.class.path")
s
}
intLoop.createInterpreter
intLoop.in = InteractiveReader.createDefault(intLoop.interpreter)
// rebind exit so people don't accidentally call System.exit by way of predef
intLoop.interpreter.beQuietDuring {
intLoop.interpreter.interpret("""def exit = println("Type :quit to resume program execution.")""")
for (p <- args) {
intLoop.interpreter.bind(p.name, p.typeStr, p.param)
println("%s: %s".format(p.name, p.typeStr))
}
}
intLoop.repl()
intLoop.closeInterpreter
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment