commands as functions (AHK v2 functions for AHK v1)

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

01 Aug 2018, 14:28

- @Helgef: else if !Value.HasKey("ToString") was supposed to be else for Float and Integer. (Error from copying and pasting resulting from trying to match Coco's indentation style, instead of using my auto-indent script.)
- Thanks for the interesting attempt at handling ToString.

- Will Integer become Int, or is there a reason for the long name? Same goes for Str/String. [EDIT:] One reason might be because Float/Integer/String are what Type returns.

- [EDIT:] For the next update perhaps, this, or a version of it.
[v1] v2's CallbackCreate function for AHK v1. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=53457
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

09 Oct 2018, 00:34

Here is what I'm planning to use for Float/Integer/String. On balance it seemed wisest to keep String simple as this gave predictable deviations from AHK v2, whereas the alternatives were giving unpredictable deviations from AHK v2.

Code: Select all

Float(Value)
{
	if Value is number
		return Value + 0.0
	throw Exception("Type mismatch.", -1)
}
Integer(Value)
{
	if Value is number
		return Value < 0 ? Ceil(Value) : Floor(Value)
	throw Exception("Type mismatch.", -1)
}
String(Value)
{
	if !IsObject(Value)
		return "" Value
	return Value.ToString()
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

24 Apr 2019, 23:52

- For an as of yet unreleased Sort function, there's this:

Code: Select all

Sort(String, Options:="", Func:="")
{
	global zAHKFC_SortFunc
	if IsObject(Func)
	{
		zAHKFC_SortFunc := Func
		Options .= " F AHKFC_SortAux"
	}
	else if !(Func = "")
		Options .= " F " Func
	Sort, String, % Options
	return String
}
AHKFC_SortAux(Arg1, Arg2, Offset)
{
	global zAHKFC_SortFunc
	return %zAHKFC_SortFunc%(Arg1, Arg2, Offset)
}
- [EDIT:] And here's a StrCompare function:

Code: Select all

StrCompare(String1, String2, CaseSensitive:=0)
{
	local Output, SCS
	SCS := A_StringCaseSense
	if (CaseSensitive = 1)
		StringCaseSense, On
	else if (SCS = "On")
		StringCaseSense, Locale
	Output := ("" String1 > "" String2) ? 1 : ("" String1 < "" String2) ? -1 : 0
	StringCaseSense, % SCS
	return Output
}
- I'm thinking that I'll release 2 versions of the script, one with the ControlXXX/WinXXX functions unchanged, one with the attempted updates. (The updated ControlXXX/WinXXX backports are bad for quick copying and pasting to a script, as they have dependencies.)

- (I'd already advocated for the following AHK v1/v2 functionality before the ControlXXX/WinXXX changes:)
- Realistically, to fully recreate ControlXXX/WinXXX, I need a way to check if the nth parameter was passed. I.e. a direct approach, instead of using a variadic function as a workaround.
- To fully recreate WinActive/WinExist and other functions, I need a way for a custom function with the same name as a built-in function to call the built-in function e.g. A_BIF.SubStr(...).
- Testing across AHK v1/v2 would be aided if: (a) all ControlXXX functions allowed you to omit the Control parameter, (b) a two-way compatible Loop/LoopXXX were available (I have proposed a solution below).
why was LoopParse (no space) removed? - Page 4 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=41821&p=235007#p235007
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

18 Aug 2019, 18:44

Re.:
AutoHotkey v2 alpha (UPDATES) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=2120&p=288705#p288705

Code: Select all

Map(Params*)
{
	if (Params.Length() & 1)
		throw Exception("Invalid number of parameters.", -1)
	return Object(Params*)
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
kevindevm
Posts: 4
Joined: 15 Apr 2019, 23:03

Re: commands as functions (AHK v2 functions for AHK v1)

26 Feb 2020, 03:06

jeeswg wrote:
18 Aug 2019, 18:44
Re.:
AutoHotkey v2 alpha (UPDATES) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=2120&p=288705#p288705

Code: Select all

Map(Params*)
{
	if (Params.Length() & 1)
		throw Exception("Invalid number of parameters.", -1)
	return Object(Params*)
}
hey jeeswg can you update first post or upload all the funtions ? i want to start using this, thanks

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 6 guests