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?
IsFunc() change Topic is solved
Re: IsFunc() change
No we couldn't do that before either.
there were a lot of calleable methods that were missed by that - e.g. bound funcs.
there were a lot of calleable methods that were missed by that - e.g. bound funcs.
Recommends AHK Studio
Re: IsFunc() change Topic is solved
this worked before v2-a90: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.
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"
}
}
Code: Select all
if IsObject(v) && IsFunc("MyClass." k)
Re: IsFunc() change
You can check if type is func.
Edit, hello
Edit, hello
Re: IsFunc() change
ehhHelgef wrote:You can check if type is func.
Edit, hello
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..
Re: IsFunc() change
There is no list of all possible returns. However,
andtype wrote:Returns the exact type of a value.
If Value is an object, the return value is the object's class name
Re: IsFunc() change
ok thanks. didn't know a function reference object would have "class name" of "Func"Helgef wrote:There is no list of all possible returns. However,andtype wrote:Returns the exact type of a value.If Value is an object, the return value is the object's class name
so i can either do:
Code: Select all
for k,v in MyClass
{
if IsObject(v) && IsFunc("MyClass." k)
%v%(environment)
}
Code: Select all
for k,v in MyClass
{
if IsObject(v) && (Type(v) = "Func")
%v%(environment)
}
Re: IsFunc() change
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.
Cheers.
Re: IsFunc() change
Though arguably that could be intended behaviour by using a compatible interface.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.
Recommends AHK Studio
Who is online
Users browsing this forum: Rohwedder and 50 guests