Squeak を REPL (GUI なし) として起動して、Smalltalk 式を入力および評価できますか? デフォルトの画像ではこれが許可されていないことはわかっています。コマンドライン シェルからアクセスできる最小限のイメージを作成する方法に関するドキュメントはありますか?
4 に答える
これが(ハックな)解決策です:まず、OSProcessが必要なので、ワークスペースでこれを実行します:
Gofer new squeaksource:'OSProcess'; package:'OSProcess';load.
次に、これをファイル repl.st に入れます。
OSProcess thisOSProcess stdOut
nextPutAll: 'Welcome to the simple Smalltalk REPL';
nextPut: Character lf; nextPut: $>; flush.
[ |input|
[ input := OSProcess readFromStdIn.
input size > 0 ifTrue: [
OSProcess thisOSProcess stdOut
nextPutAll: ((Compiler evaluate: input) asString;
nextPut: Character lf; nextPut: $>; flush
]
] repeat.
]forkAt: (Processor userBackgroundPriority)
最後に、次のコマンドを実行します。
squeak -headless path/to/squeak.image /absolute/path/to/repl.st
Smalltalk REPL を楽しむことができるようになりました。次のコマンドを忘れずに入力してください。
Smalltalk snapshot:true andQuit:true
変更を保存したい場合。
さて、このソリューションの説明に移りましょう: OSProcess は、他のプロセスを実行し、stdin から読み取り、stdout と stderr に書き込むことができるパッケージです。OSProcess thisOSProcess
(現在のプロセス、別名squeak)でstdout AttachableFileStreamにアクセスできます。
次に、userBackgroundPriority で無限ループを実行します (他のプロセスを実行させるため)。この無限ループでは、 を使用Compiler evaluate:
して入力を実行します。
これを、ヘッドレス イメージを含むスクリプトで実行します。
Pharo 2.0 (および以下で説明する修正を加えた 1.3/1.4) では、ハッキングは必要ありません。次のスニペットは、バニラの Pharo イメージを REPL サーバーに変換します...
https://gist.github.com/2604215から:
"Works out of the box in Pharo 2.0. For prior versions (definitely works in 1.3 and 1.4), first file in https://gist.github.com/2602113"
| command |
[
command := FileStream stdin nextLine.
command ~= 'exit' ] whileTrue: [ | result |
result := Compiler evaluate: command.
FileStream stdout nextPutAll: result asString; lf ].
Smalltalk snapshot: false andQuit: true.
イメージを常に REPL にしたい場合は、コードを #startup: メソッドに入れます。それ以外の場合は、次のように、REPL モードが必要なときにコマンド ラインでスクリプトを渡します。
"/path/to/vm" -headless "/path/to/Pharo-2.0.image" "/path/to/gistfile1.st"
http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84にアクセス して、GUI なしでサーバー上で Smalltalk を実行しますか ?
プロジェクトhttp://www.squeaksource.com/SecureSqueak.htmlには、探しているものの多くを提供する可能性のあるREPLパッケージが含まれています。