Scala - Initialize REPL environment

后端 未结 2 1007
花落未央
花落未央 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)  
        }
    }
    
    0 讨论(0)
  • 2021-02-06 12:03

    There is a github project called scala-ssh-shell which may do what you want, or at least get you closer.

    0 讨论(0)
提交回复
热议问题