A_BIF.XXX(): redefine but access built-in functions
Posted: 22 May 2019, 08:14
It would be immensely useful, in AHK v1/v2, if we could redefine a built-in function, but maintain access to the original.
Would it be difficult to implement this?
A related point would be some kind of IsPassed function, to know if a particular parameter had been passed.
Here are some examples:
Thanks for reading.
Would it be difficult to implement this?
A related point would be some kind of IsPassed function, to know if a particular parameter had been passed.
Here are some examples:
Code: Select all
;A_BIF proposed functionality:
FileAppend(oParams*)
{
;warning:
MsgBox("warning: will append to:`r`n" oParams.2)
;log:
vPathLog := A_Desktop "\z log FileAppend.txt"
A_BIF.FileAppend(A_Now "`t" oParams.2 "`r`n", vPath, "UTF-8")
;warn of code that does not match your coding style, e.g. omitted parameters:
if (oParams.3 = "")
{
MsgBox("warning: blank encoding parameter:`r`n" A_ThisFunc)
oParams.3 := "UTF-8"
}
;use built-in function:
return A_BIF.FileAppend(oParams*)
}
MsgBox(oParams*)
{
;change default behaviour:
;improve MsgBox for use with copy and paste:
if oParams.HasKey(1)
oParams.1 := StrReplace(oParams.1, "`r`n", "`n")
return A_BIF.MsgBox(oParams*)
}
InputBox(oParams*)
{
;change default behaviour:
;use a version of InputBox with a bigger font, if timeout is not specified:
if (oParams.3 ~= "[Tt]\d")
return A_BIF.InputBox(oParams*)
else
return MyInputBox(oParams*)
}
Sort(oParams*)
{
;warn of code that has not been converted correctly:
if InStr(oParams.2, "F ")
MsgBox("warning: improper Sort options:`r`n" oParams.2)
}
WinExist(oParams*)
{
;backport AHK v2 functionality to AHK v1:
if InStr(oParams.1, "ahk_mode")
return MyWinExist(oParams*)
else
return A_BIF.WinExist(oParams*)
}