Scala - Initialize REPL environment

后端 未结 2 1014
花落未央
花落未央 2021-02-06 11:23

-Hi. I\'d like to embed Scala REPL with initialized environment into my app. I\'ve looked at IMain class and it seems I could do it via instance of it. The

2条回答
  •  心在旅途
    2021-02-06 11:59

    -Hi, sorry I not Scala REPL hacker but i think you can do something like:

    class YourILoop(in0: Option[BufferedReader], protected override val out: JPrintWriter)         
        extends ILoop(in0, out) {
        override def createInterpreter() {
           if (addedClasspath != "")
              settings.classpath append addedClasspath
    
              intp = new ILoopInterpreter
              val x = 3;
              intp.bind("x", x)
        }
    }
    object Run {
        def errorFn(str: String): Boolean = {
          Console.err println str
          false
        }
    
        def process(args: Array[String]): Boolean = {
            val command = new GenericRunnerCommand(args.toList, (x: String) => errorFn(x))
            import command.{ settings, howToRun, thingToRun }
            new YourILoop process settings
        }
        def main(args: Array[String]) {
            process(args)  
        }
    }
    

提交回复
热议问题