You can do the opposite and invert the result.
Code: Select all
test("foo")
test(1)
test(this){
t:="_" type(this)
if isfunc(t) && !IsGlobalFunc(t)
%t%()
else
MsgBox("no")
_string() => MsgBox("string")
_object() => MsgBox("object")
}
_Integer() => MsgBox(":(")
IsGlobalFunc(f) => IsFunc(f)
Or you can use a more predictable data set; i.e. one you define explicitly.
Code: Select all
test("foo")
test(1)
test(this){
fswitch := {
string: Func("_string"),
object: Func("_object")
}
if f := fswitch[type(this)]
%f%()
else
MsgBox("no")
_string() => MsgBox("string")
_object() => MsgBox("object")
}
_Integer() => MsgBox(":(")
The second case might be more efficient.
fswitch can be static if the functions are not closures. The functions could be defined inline (in fswitch) in this particular example, but
Func("_string") is resolved at load time anyway.
The first case might be optimized slightly by reducing the number of times the function name must be resolved:
Code: Select all
if (f := Func(t)) && !IsGlobalFunc(t)
%f%()
However, searching for a function which doesn't exist is slow.
Both
!IsGlobalFunc() and
IsSubFunc() have a problem: what if the function is nested, but in an outer function (not the current function)? You can define an
IsOuterFunc() in the outer function...
IsGlobalFunc has another issue: what if there
is a nested function, but there is also a global function with the same name?
Code: Select all
test("foo")
test(1)
test(this){
t:="_" type(this)
if (f := Func(t)) && !IsFuncGlobal(f)
%f%()
else
MsgBox("no")
_string() => MsgBox("string")
_object() => MsgBox("object")
}
_Integer() => MsgBox(":(")
_string() => MsgBox(":(")
IsFuncGlobal(f) => Func(f.Name) = f