Page 1 of 1

Alternative for IsFunc function in V2?

Posted: 28 Jul 2021, 13:28
by AHK_user
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.

Re: Alternative for IsFunc function

Posted: 28 Jul 2021, 13:36
by HotKeyIt

Code: Select all

fun(){
}
MsgBox Type(fun)

Re: Alternative for IsFunc function in V2?

Posted: 28 Jul 2021, 14:07
by swagfag
  • operator is
  • check for Call/__Call props or methods(and in the bases, too)

Re: Alternative for IsFunc function in V2?

Posted: 28 Jul 2021, 15:05
by AHK_user
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
}

Re: Alternative for IsFunc function in V2?

Posted: 28 Jul 2021, 15:29
by swagfag

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)

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

Posted: 28 Jul 2021, 16:31
by AHK_user
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...

Re: Alternative for IsFunc function in V2?

Posted: 02 Aug 2021, 10:43
by guest3456
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