The whole point of overriding Call is to change what it does. Usually it is specifically to avoid having it create a new object that you're going to discard, such as by
returning the result of MsgBox instead of an object. If you define it as
static Call() => MsgBox(A_ThisFunc), obviously it's only going to call MsgBox and not create any objects.
Obj() is the same as
Obj.Call() for nearly all types of values, including classes; i.e. it's just a normal method call, except that
Obj() never calls the __Call meta-method. If you redefine a method, the previous definition is only relevant if you call it.
(ie the one belonging to Object in this case)
In the case of
class Parent, yes. It should apply to all built-in classes
derived from Object which can be instantiated by calling
ClassName(). Look for NewObject<> in the
"class tree".
Other
classes which do not derive from Object have different built-in functions in place of Call. ComValue.Call is effectively just the former ComObject() function, ComArray.Call is ComObjArray(), etc. Float(), Integer() and String() are the same functions as before the classes, just adjusted to exclude the class object parameter.
heres the next question for u
Where? I see no question.
Regarding your unreasonable demand to fix code,
You can't extend a COM wrapper. It is like a Primitive;
base is determined by type, not the other way around.
"Construction and Destruction" is a sub-heading of "Custom
Objects", although
class can obviously be used with non-Object classes. The documentation is perhaps a bit outdated.
It
seems your demand was only unreasonable, not impossible, as this code does "compile":
Code: Select all
#Requires AutoHotkey v2.0-a136-feda41f4
a := IUnknown()
MsgBox a.Ptr = 0 ; true
MsgBox a is IUnknown ; true
MsgBox a is ComValue ; true
MsgBox ComObjType(a) ; 13, ie 0xD VT_UNKNOWN
someValidNakedIUnknownPtr := ObjPtrAddRef({})
b := IUnknown(someValidNakedIUnknownPtr)
MsgBox b.Ptr = someValidNakedIUnknownPtr ; true
MsgBox b is IUnknown ; true
MsgBox b is ComValue ; true
MsgBox ComObjType(b) ; 13, ie 0xD VT_UNKNOWN
class IUnknown {
static __New() {
this.Prototype := ComValue.Prototype
}
static Call(Ptr := 0) {
return ComValue(13, Ptr)
}
}
; This is not intended to be useful. ;)
cant use the monkey patch method either, since it complains about "the base being invalid"
I don't think you're using the term "monkey patch" correctly. One would monkey patch COM wrappers by modifying ComValue.Prototype. I assume you attempted to assign IUnknown.Prototype as the base of an Object. An Object is not a ComValue any more than it is a Primitive.