IsFunc() change

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Guest3456nli

IsFunc() change

29 Jun 2018, 11:30

In a90:

"Changed IsFunc() and Func() to require a function name. Passing an object is now an error."

Before we could iterate through a class's items with a `for k,v in class` and then check

if IsObject(v) && IsFunc(v)

to know whether the item was a callable method. Now we can't do that anymore. How can we figure out if the item is a callable method?
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: IsFunc() change

29 Jun 2018, 13:14

No we couldn't do that before either.
there were a lot of calleable methods that were missed by that - e.g. bound funcs.
Recommends AHK Studio
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: IsFunc() change

29 Jun 2018, 14:25

nnnik wrote:No we couldn't do that before either.
there were a lot of calleable methods that were missed by that - e.g. bound funcs.
this worked before v2-a90:

Code: Select all

environment := new MyClass

for k,v in MyClass
{
   ; call all methods in MyClass
   if IsObject(v) && IsFunc(v)
      %v%(environment)
}


class MyClass
{
   one := "one"
   
   two() {
      msgbox "two"
   }

   three() {
      msgbox "three"
   }
}

looks like this is how I have to do it now:

Code: Select all

   if IsObject(v) && IsFunc("MyClass." k)

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: IsFunc() change

29 Jun 2018, 14:57

You can check if type is func.

Edit, hello :wave:
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: IsFunc() change

29 Jun 2018, 15:24

Helgef wrote:You can check if type is func.

Edit, hello :wave:
ehh

https://lexikos.github.io/v2/docs/commands/Type.htm
https://lexikos.github.io/v2/docs/commands/is.htm

i don't see function types listed in either..

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: IsFunc() change

29 Jun 2018, 15:45

There is no list of all possible returns. However,
type wrote:Returns the exact type of a value.
and
If Value is an object, the return value is the object's class name
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: IsFunc() change

29 Jun 2018, 17:24

Helgef wrote:There is no list of all possible returns. However,
type wrote:Returns the exact type of a value.
and
If Value is an object, the return value is the object's class name
ok thanks. didn't know a function reference object would have "class name" of "Func"

so i can either do:

Code: Select all

for k,v in MyClass
{
   if IsObject(v) && IsFunc("MyClass." k)
      %v%(environment)
}
or

Code: Select all

for k,v in MyClass
{
   if IsObject(v) && (Type(v) = "Func")
      %v%(environment)
}

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: IsFunc() change

30 Jun 2018, 06:09

Your first alternative have the benefit of not yielding a false positive for something like v := { base : {__class : 'Func'} }. I would probably not consider that possibility, and be happy with if type(v) == 'Func'.

Cheers.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: IsFunc() change

30 Jun 2018, 06:21

Helgef wrote:Your first alternative have the benefit of not yielding a false positive for something like v := { base : {__class : 'Func'} }. I would probably not consider that possibility, and be happy with if type(v) == 'Func'.

Cheers.
Though arguably that could be intended behaviour by using a compatible interface.
Recommends AHK Studio

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: arcylix, Panaku, qcgreywolf, redrum, zabbn and 36 guests