-
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathInstanceOf.ts
More file actions
21 lines (19 loc) · 663 Bytes
/
InstanceOf.ts
File metadata and controls
21 lines (19 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export function __TS__InstanceOf(this: void, obj: LuaClassInstance, classTbl: LuaClass): boolean {
if (typeof classTbl !== "object") {
throw "Right-hand side of 'instanceof' is not an object";
}
if (classTbl[Symbol.hasInstance] !== undefined) {
// eslint-disable-next-line no-implicit-coercion
return !!classTbl[Symbol.hasInstance]!(obj);
}
if (typeof obj === "object") {
let luaClass = obj.constructor;
while (luaClass !== undefined) {
if (luaClass === classTbl) {
return true;
}
luaClass = luaClass.____super!;
}
}
return false;
}