ParamToObj() - Convert command line parameters to object

Post your working scripts, libraries and tools for AHK v1.1 and older
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

ParamToObj() - Convert command line parameters to object

10 Jul 2014, 07:20

Code: Select all

; Example:
; 	Save this file to ParamToObj_Sample.ahk, then run with parameters:
; 		ParamToObj_Sample.ahk /x 20 -novalue1 -y 14 /novalue2 --width=710 --novalue3 --height 90 WillBeIgnored /title:"hi !"
; 	The result will be:
; 		param.height = 90
; 		param.novalue1 = 
; 		param.novalue2 = 
; 		param.novalue3 = 
; 		param.title = hi !
; 		param.width = 710
; 		param.x = 20
; 		param.y = 14

param := ParamToObj()
For k, v in param
	param_list .= "param." k " = " v "`n"
MsgBox, % param_list

ParamToObj() {
	global 0
	obj := {}

	Loop, %0%
	{
		param := %A_Index%

		If RegExMatch(param, "^(/|-)+(\w+)(\W(.+))?$", match) {
			obj[match2] := match4
			key         := match2
		}
		Else If (key != "")
			obj[key] := param, key := ""
	}

	Return obj
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 116 guests