Page 1 of 1

A_BIF.XXX(): redefine but access built-in functions

Posted: 22 May 2019, 08:14
by jeeswg
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:

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*)
}
Thanks for reading.

Re: A_BIF.XXX(): redefine but access built-in functions

Posted: 22 May 2019, 12:19
by Helgef
This was already mentioned in thoughts for v2 at some point iirc, I think the suggestion was base.somefunc(). I don't really like either one of these suggestions, but agree that accessing bifs should be possible. I have implemented different means to achieve this, but non would be applicable to v1.

re. IsPassed, I do not think it is related, but for a variadic function you can use haskey.

Cheers.

Re: A_BIF.XXX(): redefine but access built-in functions

Posted: 22 May 2019, 22:28
by lexikos
I have some v2 implementation changes planned that may affect how this could be done.

It is unlikely that I will be making any significant changes to v1 that I have not already developed.

Re: A_BIF.XXX(): redefine but access built-in functions

Posted: 30 May 2019, 17:44
by jeeswg
@Helgef: I mentioned IsPassed since it also related to the core functionality of functions. Also, like A_BIF, it would be particularly useful for backporting functions, especially those with ByRef parameters (where variadic parameters wouldn't be an option).
A_BIF seems relatively intuitive/elegant, although I wouldn't mind what name was chosen.

@lexikos: Thanks for the info.

In terms of backporting AHK v2 functions to AHK v1, via the source code, these 3 small additions would be useful:

Code: Select all

add support for obj.Ptr:
DllCall, NumGet, NumPut

add support for obj.Hwnd:
WinActive, WinExist

add support for 'A_V2Mode' (to turn 'AHK v2' mode on/off):
InStr, RegExMatch, RegExReplace, SubStr
StrPut

==============================

other AHK v1 functions for reference:
Abs, Ceil, Exp, Floor, Log, Ln, Max, Min, Mod, Round, Sqrt
Sin, Cos, Tan, ASin, ACos, ATan
Format

Array, ComObjXXX, Object, ObjXXX
Chr, Ord
Exception
FileExist, FileOpen
Func
GetKeyName, GetKeySC, GetKeyState, GetKeyVK
Hotstring
IL_Add, IL_Create, IL_Destroy
IsByRef, IsFunc, IsLabel, IsObject
LoadPicture
LTrim, RTrim, Trim
OnClipboardChange, OnError, OnExit, OnMessage
StrGet, StrLen, StrReplace, StrSplit
VarSetCapacity

deprecated AHK v1 functions:
Asc
LV_XXX, SB_XXX, TV_XXX
RegisterCallback

Re: A_BIF.XXX(): redefine but access built-in functions

Posted: 31 May 2019, 00:35
by Helgef
A_BIF seems relatively intuitive/elegant, although I wouldn't mind what name was chosen.
I wouldn't care very much about which name was chosen if it was implemented as a biv. I don't think there is anything elegant or intuitive about a_bif though, base is a real word at least.

Byref variadic would be more generally useful than ispassed.

Cheers.

Re: A_BIF.XXX(): redefine but access built-in functions

Posted: 21 Jun 2019, 04:53
by Delta Pythagorean
Couldn't you just use a super global for this instead?