I want to implement a function in scala that can parse string of a source code (a class object) and compile it to an object in the run time.
For example, the function is what I have tried so far. My goal is that run it compiled in run-time environment, I can use it constructor or its function. This code has run-time error but I don't understand the how to fix the reflect class error. Thanks!
object test {
def main(args: Array[String]): Unit = {
val m = universe.runtimeMirror(getClass.getClassLoader)
val tb = m.mkToolBox()
val clazz = tb.compile(tb.parse("class insideclass {\n val model_field = 5\n def insideclass(model: Int) = {\n val model_field = model \n } \n\n def test() : Int = {\n model_field\n }\n\n}\nscala.reflect.classTag[insideclass].runtimeClass"))().asInstanceOf[Class[_]]
val classinside = universe.typeOf[Class[_]].typeSymbol.asClass
val ctor = universe.typeOf[Class[_]].declaration(universe.nme.CONSTRUCTOR).asMethod
val cm=m.reflectClass(classinside)
val ctorm=cm.reflectConstructor(ctor)
println(ctorm(10).test())
}
}