nnnik wrote: ↑15 Jan 2020, 06:25
would break your idea.
nnnik is right.
If type string contain some 'Type' it is not the solution.
Very elegant solution from
swagfag but actually not the complete solution.
Code: Select all
class ClassFunction {
Call() {
MsgBox('ClassFunction')
} }
class holder {
__New(acti) {
MsgBox('argument.HasMethod("Call") = ' acti.HasMethod('Call'))
this.acti:= (acti.HasMethod('Call')? acti: (*)=>MsgBox('default')).Bind(this)
} }
h:= holder.new(ClassFunction.new())
/* ---------------------------
[a108] TEST.ahk
---------------------------
Error: This value of type "ClassFunction" has no method named "Bind".
Line#
011: {
000: }
012: {
013: MsgBox(acti.HasMethod('Call'))
014: {
014: Return MsgBox('default')
014: }
---> 014: this.acti:= (acti.HasMethod('Call')? acti: (*)=>MsgBox('default')).Bind(this)
016: }
018: h := holder.new(Func('Function'))
019: h.acti.call()
020: h := holder.new(ClassFunction.new())
021: h.acti.call()
023: {
024: While (this.__Class != 'Any')
The current thread will exit.
---------------------------
OK
---------------------------*/
h.acti.call()
I made some tests and the right question is:
Is there in inheritance chain some BASE that is 'Func' (in this case).
And I make a small function that return TRUE if there so BASE and FALSE else.
Code: Select all
isType(this, type) {
while(this.__Class != 'Any')
if(this.__Class == type)
return 1
else this:= this.base
return 0
}
As everything in AHKv2.0 is some kind of OBJECT, all 'things' have property '__Class' that contain name of given OBJECT.
For example:
Code: Select all
1 = Integer.Integer.Number.Primitive.Any
1.1 = Float.Float.Number.Primitive.Any
"" = String.String.Primitive.Any
()=> = Func.Func.Object.Any
Now what the function isType(this, type) can do?
Code: Select all
isType(1, 'Integer') ; TRUE
isType(1, 'Number') ; TRUE
isType(1.1, 'Integer') ; FALSE
isType(1.1, 'Number') ; TRUE
And lets return to example.
Code: Select all
class ClassFunction {
Call() {
MsgBox('ClassFunction')
} }
class holder {
__New(acti) {
MsgBox('argument.HasMethod("Call") = ' acti.HasMethod('Call'))
this.acti:= (isType(acti, 'Func')? acti: (*)=>MsgBox('default')).Bind(this)
} }
h:= holder.new((this)=>MsgBox('Noname function >> ' this.__Class)) ;set acti as function
h.acti.call()
h:= holder.new(ClassFunction.new()) ;set acti as default function
h.acti.call()
Now we exactly know is that value has base 'Func'.
EDIT: An example that can return fake positive result.
Code: Select all
class Func {
Call() {
MsgBox('ClassFunction')
} } ;In this case Func.Func.Object.Any
I think in the future reserved words cannot be used as variable or class names.