-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathIsType.ahk
75 lines (74 loc) · 2.56 KB
/
IsType.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Include <Is>
Type(Value)
{
local
; This should be updated when a new built-in type is added to AutoHotkey.
static BoundFunc := Func("Type").Bind("")
static ComObjEnum := ComObjCreate("Scripting.Dictionary")._NewEnum()
static Enum := {}._NewEnum()
static File := FileOpen(a_scriptfullpath, "r")
static Func := Func("Type")
static RegExMatch, _ := RegExMatch("a" ,"O)a", RegExMatch)
; If you try to convert the above to expressions and get the addresses, the
; result is incorrect.
static TypeFromAddress := {NumGet(&BoundFunc): "BoundFunc"
,NumGet(&ComObjEnum): "ComObject.Enumerator"
,NumGet(&Enum): "Object.Enumerator"
,NumGet(&File): "File"
,NumGet(&Func): "Func"
,NumGet(&RegExMatch): "RegExMatch"}
if (Is(Value, "object"))
{
if (TypeFromAddress.HasKey(NumGet(&Value)))
{
Result := TypeFromAddress[NumGet(&Value)]
}
else if (ComObjType(Value) != "")
{
if (ComObjType(Value) & 0x2000)
{
Result := "ComObjArray"
}
else if (ComObjType(Value) & 0x4000)
{
Result := "ComObjRef"
}
else if ( (ComObjType(Value) == 9 or ComObjType(Value) == 13)
and ComObjValue(Value) != 0 )
{
Result := ComObjType(Value, "Class") != "" ? ComObjType(Value, "Class")
: "ComObject"
}
else
{
Result := "ComObj"
}
}
else
{
; This is complicated because it must avoid running meta-functions.
Result := ObjHasKey(Value, "__Class") ? "Class" : ""
CurrentObject := Value
while (Result == "" and CurrentObject != "")
{
try
{
Result := ObjRawGet(CurrentObject, "__Class")
CurrentObject := ObjGetBase(CurrentObject)
}
catch
{
CurrentObject := ""
}
}
Result := Result == "" ? "Object" : Result
}
}
else
{
Result := Is(Value, "integer") ? "Integer"
: Is(Value, "float") ? "Float"
: "String"
}
return Result
}