Skip to content

Instantly share code, notes, and snippets.

@paulp
Created October 22, 2012 15:02
Show Gist options
  • Save paulp/3931918 to your computer and use it in GitHub Desktop.
Save paulp/3931918 to your computer and use it in GitHub Desktop.
def breakIf[T: ClassTag](assertion: => Boolean, args: NamedParam*): Unit =
if (assertion) break[T](args.toList)
// start a repl, binding supplied args
def break[T: ClassTag](args: List[NamedParam]): Unit = savingContextLoader {
val msg = if (args.isEmpty) "" else " Binding " + args.size + " value%s.".format(
if (args.size == 1) "" else "s"
)
echo("Debug repl starting." + msg)
val repl = new ILoop {
override def prompt = "\ndebug> "
}
repl.settings = new Settings(echo)
repl.settings.embeddedDefaults[T]
repl.createInterpreter()
repl.in = new JLineReader(new JLineCompletion(repl))
// rebind exit so people don't accidentally call sys.exit by way of predef
repl.quietRun("""def exit = println("Type :quit to resume program execution.")""")
args foreach (p => repl.bind(p.name, p.tpe, p.value))
repl.loop()
echo("\nDebug repl exiting.")
repl.closeInterpreter()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment