Alternative for IsFunc function in V2? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Alternative for IsFunc function in V2?

28 Jul 2021, 13:28

Is there an alternative for the removed IsFunc function in AHK V2?

I do not want to run the function itself (for this we could use try catch..), I want to know if the function exist for a convertor script.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Alternative for IsFunc function in V2?

28 Jul 2021, 14:07

  • operator is
  • check for Call/__Call props or methods(and in the bases, too)
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Alternative for IsFunc function in V2?

28 Jul 2021, 15:05

swagfag wrote:
28 Jul 2021, 14:07
  • operator is
  • check for Call/__Call props or methods(and in the bases, too)
Thanks for the tips, I am just started to convert my mind to V2, excellent brain training material :), but I feel like a noob again :lol: .

Code: Select all

#SingleInstance Force
#Requires AutoHotkey 2.0-beta.1

FunctionList := "
(
Abs
ASin
ACos
ATan
Buffer
CallbackCreate
CallbackFree
CaretGetPos
Ceil
Chr
ClipboardAll
ComCall
ComObjActive
ComObjArray
ComObjConnect
ComObject
ComObjFlags
ComObjFromPtr
ComObjGet
ComObjQuery
ComObjType
ComObjValue
ComValue
ControlFindItem
ControlGetChecked
)"

Loop Parse, FunctionList, "`n"
{
	result.= A_LoopField " : " IsFunc(A_LoopField) "`n"
}
MsgBox(result)

return

IsFunc(FunctionName){
	Try{
		return %FunctionName%.MaxParams
	}
	Catch{
		return 0
	}
	return
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Alternative for IsFunc function in V2?

28 Jul 2021, 15:29

Code: Select all

IsFunc(FunctionName){
	Try{
		return %FunctionName%.MaxParams
	}
	Catch{
		return 0
	}
	return
}
is at best a misnomer(perhaps u meant to write TryGetMaxParamsOrNull()?) and at worst a broken reimplementation of IsFunc(incorrect results for nullary and variadic functions, as well as ones of any arity that only declare optional parameters)
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Alternative for IsFunc function in V2?  Topic is solved

28 Jul 2021, 16:31

swagfag wrote:
28 Jul 2021, 15:29

Code: Select all

IsFunc(FunctionName){
	Try{
		return %FunctionName%.MaxParams
	}
	Catch{
		return 0
	}
	return
}
is at best a misnomer(perhaps u meant to write TryGetMaxParamsOrNull()?) and at worst a broken reimplementation of IsFunc(incorrect results for nullary and variadic functions, as well as ones of any arity that only declare optional parameters)
You are correct, I wanted to have the old ahk V1 IsFunc function, but read the documentation of IsFunc wrong.


This should be the correct code:

Code: Select all

IsFunc(FunctionName){
	Try{
		return %FunctionName%.MinParams+1
	}
	Catch{
		return 0
	}
	return
}
:think: Maybe a good idea to make a library of deleted V1 functions that can be used in V2 to make the transition easier...
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Alternative for IsFunc function in V2?

02 Aug 2021, 10:43

swagfag wrote:
28 Jul 2021, 14:07
  • operator is
  • check for Call/__Call props or methods(and in the bases, too)
https://www.autohotkey.com/boards/viewtopic.php?p=382662#p382662


Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Noitalommi_2 and 37 guests