Skip to content

Commit 4a3fe03

Browse files
authored
feat: custom type check method
2 parents 4effbb3 + efed9c9 commit 4a3fe03

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

class_loader.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,30 @@ do
154154
end
155155
}
156156

157+
local type = type
158+
local getmetatable = getmetatable
159+
local function enhancedType(object)
160+
local typ = type(object)
161+
162+
if typ == "table" then
163+
local objectType = object.__type
164+
if objectType == "EnumValue" then
165+
local declaringClass = object._declaringClass
166+
if declaringClass then
167+
typ = declaringClass.__name or typ
168+
end
169+
elseif objectType == "Enum" then
170+
typ = object.__name .. "#Template"
171+
elseif getmetatable(object) == nil then --This is an uninitialised class.
172+
typ = object.__name and (object.__name .. "#Template") or typ
173+
else
174+
typ = object.__name or typ
175+
end
176+
end
177+
178+
return typ
179+
end
180+
157181
baseEnvironment.__index = baseEnvironment
158182
setmetatable(baseEnvironment, {__index = _G})
159183

@@ -169,6 +193,7 @@ do
169193
__type = "Package",
170194
__isPackage = true,
171195
_G = _G,
196+
type = enhancedType,
172197
pairs = pairs,
173198
ipairs = ipairs
174199
}

0 commit comments

Comments
 (0)