Skip to content

Instantly share code, notes, and snippets.

@hoppfrosch
Created October 9, 2013 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoppfrosch/6899710 to your computer and use it in GitHub Desktop.
Save hoppfrosch/6899710 to your computer and use it in GitHub Desktop.
Named functions parameters using variadic and JSON-Syntax #ahk #script #snippet
; Named parameters for functions
;
; Credits: named parameters by lexikos (http://www.autohotkey.com/board/topic/62504-variadic-functions)
; Note the Brackets around the parameters and the trailing star {...}*!!! (Brackets: JSON - Star: Variadic ...)
Test({WinTitle: "ahk_class Notepad", ExcludeTitle: "Untitled", Cmd: "PID"}*)
Test2({WinTitle: "ahk_class Notepad", ExcludeTitle: "Untitled2", Cmd: "PID2"}*)
; Simple Variadic: All parameters are accesible through prms-Array
Test(prms*) {
MsgBox % "Cmd: " prms.Cmd "`nWinTitle: " prms.WinTitle "`nWinText: " prms.WinText . "`nExcludeTitle: " prms.ExcludeTitle "`nExcludeText: " prms.ExcludeText
return out
}
; Named Arguments are accessible directly by name
Test2(Cmd="ID", WinTitle="A", WinText="", ExcludeTitle="", ExcludeText="") {
MsgBox % "Cmd: " Cmd "`nWinTitle: " WinTitle "`nWinText: " WinText . "`nExcludeTitle: " ExcludeTitle "`nExcludeText: " ExcludeText
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment