Comment detail

コマンドライン引数の取得 (Nested Flatten)

Smalltalk では処理系依存です。Squeak Smalltalk では、 起動時に

Squeak my.image program.st a b c d

のように記述し、スクリプト中では SmalltalkImage>>#getSystemAttribute: の引数 3 以降で取り出せます。

1
2
3
4
5
6
| args |
World findATranscript: nil.
args := (3 to: 6) collect: [:idx | SmalltalkImage current getSystemAttribute: idx].
Transcript cr; show: args

"=> #('a' 'b' 'c' 'd') "

GNU Smalltalk。Cのgetoptっぽい機能が付いてます。

1
2
3
4
5
6
Smalltalk arguments print.
Smalltalk arguments: '-c -d:' do: [:o :n| {o. n} print ]!
"
$ gst 114.st -a a b -c -dFuga
=> ('a' 'b' '-c' '-dFuga' )(nil 'a' )(nil 'b' )($c nil )($d 'Fuga' )
"

Index

Feed

Other

Link

Pathtraq

loading...