AutoHotkeyのスクリプトへの引数を一度に取得し、処理しやくすする
AutoHotkeyのスクリプトへの引数の値に関しては、1番目の引数ならば%1%、2番目の引数ならば%2%のように、一つずつ明示的に取り出さなくてはならない。ただし、%0%には引数の総数が格納されているので、Loopを用いてこれを展開すれば、複数の引数をより取り出しやすくなる。
そこで、全ての引数をObject型で返すようにしてみた。
;; test_script_parameter.ahk 2 4 5 3 get_script_parameters() ;; -> parse Script_Parameters ;; and return the object of those parameters ;; {1:3, 2:4, 3:5, 4:3} MsgBox,% get_script_parameters().MaxIndex() ;; 4 for index, value in get_script_parameters() { MsgBox,% index . ": " . value . "`n" } ;; 1: 2 ;; 2: 4 ;; 3: 5 ;; 4: 3 MsgBox,% get_script_parameters()[3] ;; 5 return get_script_parameters(){ global static Script_Parameters := Object() if ("" == Script_Parameters.MaxIndex()) { Loop, %0% { Script_Parameters.insert(%A_Index%) } } return Script_Parameters }