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

Propose new features and changes
User avatar
jeeswg
Posts: 6829
Joined: 19 Dec 2016, 01:58
Location: UK

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

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:

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4002
Joined: 17 Jul 2016, 01:02
Contact:

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

22 May 2019, 12:19

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.
lexikos
Posts: 6653
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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

22 May 2019, 22:28

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.
User avatar
jeeswg
Posts: 6829
Joined: 19 Dec 2016, 01:58
Location: UK

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

30 May 2019, 17:44

@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
Last edited by jeeswg on 02 Jun 2019, 13:38, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4002
Joined: 17 Jul 2016, 01:02
Contact:

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

31 May 2019, 00:35

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.
User avatar
Delta Pythagorean
Posts: 482
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

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

21 Jun 2019, 04:53

Couldn't you just use a super global for this instead?

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 1 guest