Clozure CL でコンパイルしたバイナリの引数処理
どうやらインタプリタとして動作させる場合と、バイナリにした場合とで引数の渡し方が異なるようだ。以下の実装だとスクリプトではうまく引数を処理してくれるが、バイナリにすると引数を取得できなかった。
(defun test () (if (equal 3 (length *unprocessed-command-line-arguments*)) (format t "~A,~A,~A~%" (first *unprocessed-command-line-arguments*) (second *unprocessed-command-line-arguments*) (third *unprocessed-command-line-arguments*)) (format t "Usage: test2 $1 $2 $3~%")))
もちろん、インタプリタではこの実装で問題ない。
バイナリにする場合は *command-line-argument-list* を使用する。そして、C と同じように第一引数は実行バイナリの名前になるようだ。
(defun test () (if (equal 3 (length *command-line-argument-list*)) (format t "~A,~A,~A~%" (first *command-line-argument-list*) (second *command-line-argument-list*) (third *command-line-argument-list*)) (format t "Usage: test1 $1 $2 $3~%")))
(save-application "test" :toplevel-function #'test :prepend-kernel t) 後、test を実行したら以下のようになる。
$ ./test Usage: test $1 $2 $3 $ ./test 1 Usage: test $1 $2 $3 $ ./test 1 2 ./test,1,2 $ ./test 1 2 3 Usage: test $1 $2 $3 $