2012-09-27 11 views
6

-Hi。 Scala REPLをで初期化した環境で埋め込んでみたい私はIMainクラスを見てきました。インスタンスが作成され、intpprocess()のpublic varに格納されます。Scala - REPL環境の初期化

process()(REPLの前など)の前にいくつかの名前をバインドしたり、インポートを追加するにはどうすればよいですか? intpがまだ作成されていないため

次のコードは、(=> NPE)3行目で失敗:

val x = 3 
    val interp = new ILoop 
    interp.bind("x", x) // -> interp.intp.bind("x", x) 
    val settings = new Settings 
    settings.usejavacp.value = true 
    interp.process(settings) 

がyou-がありがとうございました。

UPDATE:createInterpreter()が、残念ながら動作しませんオーバーライド:

val x = 3 
    val interp = new ILoop { 
     override def createInterpreter() { 
      super.createInterpreter() 
      intp.bind("x", x) // -> interp.intp.bind("x", x) 
     } 
    } 
    val settings = new Settings 
    settings.usejavacp.value = true 
    interp.process(settings) 

インタプリタは、入力に貼り付ける(デッドロックのように見える、上記のコードのみで発生):

x: Int = 3 
Failed to created JLineReader: java.lang.NoClassDefFoundError: scala/tools/jline/console/completer/Completer 
Falling back to SimpleReader. 
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_06-icedtea). 
Type in expressions to have them evaluated. 
Type :help for more information. 

scala> println 
<infinite_sleep> 

おかげで提案のためdvigal。

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) 
    } 
} 

答えて

4

あなたがやりたいこと、あるいは少なくとも近いあなたを得る可能性があるscala-ssh-shell呼ばgithubのプロジェクトがあります:

+0

を更新しました。私はプロジェクトを見て、それは動作するようです。ありがとうございました。 – woky

1

-Hiは、残念私はないScalaのREPLのハッカーが、私はあなたのような何かを行うことができると思います。

+0

いいです、残念ながら、それはうまくいきません、私は答えを – woky