Skip to content

Instantly share code, notes, and snippets.

@leon
Created March 29, 2012 06:33
Show Gist options
  • Save leon/2234159 to your computer and use it in GitHub Desktop.
Save leon/2234159 to your computer and use it in GitHub Desktop.
Compile scala programatically
import scala.tools.nsc.{Interpreter,Settings}
var i = new Interpreter(new Settings(str => println(str)))
var res = Array[Any](null)
i.beQuietDuring({
i.bind("result", "Array[Any]", res)
i.interpret("class Fred {def foo = 3}")
i.interpret("result(0) = new Fred")
})
println(res(0).asInstanceOf[{def foo: Int}].foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment