If I understand things correctly, whenever you call a method of a class __Call() is invoked.
This recursively searches the object (and its base classes) for the key that is the function name.
If that key exists, call the function.
Else return ""
Is there example code of the default __Call() method?
Can you override __Call() to invoke a specific function when there is no method passed?
For example:
%myClassInstance%() ; calls __Call() [with key="" ?] -- how do I make this call myClassInstance.DoStuff() ?
In my particular case, I am making a wrapper class to make binding sub routines, functions, and class methods all use one syntax.
So it makes sense that %myClassInstance%() would simply call the label / function / class method exactly like calling a funcObject.
[Solved] Override __Call() when there is no key()? Topic is solved
[Solved] Override __Call() when there is no key()?
Last edited by kinnex on 21 Jun 2016, 12:14, edited 1 time in total.
Re: Override __Call() when there is no key()? Topic is solved
Code: Select all
instance := new Functor()
%instance%()
return
class Functor
{
__Call(method, args*)
{
if (IsObject(method)) ; if class object is used as method(usually achieved when nesting)
return this.Call(method, args*)
if (method == "") ; %instance%() syntax
return this.Call(args*)
}
Call(args*)
{
MsgBox Hello
}
}
Re: Override __Call() when there is no key()?
Thank you, that is exactly what I needed to do.
Re: [Solved] Override __Call() when there is no key()?
I actually updated that documentation a few days ago, but only uploaded it just now (you may need to refresh). The original Objects as Functions section hadn't been updated until then. I basically just defined a class using the recommendations on the Function Objects page, updated two examples to use it and moved one from the former page to the latter.
Who is online
Users browsing this forum: Google [Bot] and 190 guests