-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleclass_extras.txt
101 lines (76 loc) · 2.74 KB
/
middleclass_extras.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
--@name Middleclass Extras
--@author legokidlogan
--@shared
if isInstanceOf then return end
-- Whether or not obj is an instance of class, or a subclass of it
function isInstanceOf( obj, class )
if type( obj ) ~= "table" then return false end
local func = obj.isInstanceOf
if not func then return false end
return func( obj, class )
end
-- Whether or not obj is a subclass of class, but not a direct instance of it
function isSubclassOf( obj, class )
if type( obj ) ~= "table" then return false end
local func = obj.isSubclassOf
if not func then return false end
return func( obj, class )
end
-- Whether or not obj is a direct instance of class
function isClass( obj, class )
if type( obj ) ~= "table" then return false end
local objClass = obj.class
if not objClass then return false end
return objClass == class
end
-- Whether or not obj's class name is exactly className
function isClassByName( obj, className )
if type( obj ) ~= "table" then return false end
local objClass = obj.class
if type( objClass ) ~= "table" then return false end
local objClassName = objClass.name
if not objClassName then return false end
return objClassName == className
end
--[[
- Whether or not tbl is a middleclass instance object.
- tbl must be a table, otherwise this will error.
- This is faster than isInstanceObject() by skipping the type check.
--]]
function isTableInstanceObject( tbl )
return isClassObject( tbl.class )
end
-- Whether or not obj is a middleclass instance object.
function isInstanceObject( obj )
if type( obj ) ~= "table" then return false end
return isTableInstanceObject( obj )
end
--[[
- Whether or not tbl is a middleclass class object.
- tbl must be a table, otherwise this will error.
- This is faster than isClassObject() by skipping the type check.
--]]
function isTableClassObject( tbl )
if tbl.name == nil then return false end
if tbl.subclass == nil then return false end
if tbl.allocate == nil then return false end
return true
end
-- Whether or not obj is a middleclass class object
function isClassObject( obj )
if type( obj ) ~= "table" then return false end
return isTableClassObject( obj )
end
--[[
- Whether or not tbl is a middleclass object (class or instance).
- tbl must be a table, otherwise this will error.
- This is faster than isMiddleclassObject() by skipping the type check.
--]]
function isTableMiddleclassObject( tbl )
return isTableInstanceObject( tbl ) or isTableClassObject( tbl )
end
-- Whether or not obj is a middleclass object (class or instance).
function isMiddleclassObject( obj )
if type( obj ) ~= "table" then return false end
return isTableMiddleclassObject( obj )
end