Created
October 9, 2013 11:21
-
-
Save hoppfrosch/6899710 to your computer and use it in GitHub Desktop.
Named functions parameters using variadic and JSON-Syntax #ahk #script #snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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