-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathClassExtends.ts
More file actions
20 lines (17 loc) · 1.13 KB
/
ClassExtends.ts
File metadata and controls
20 lines (17 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export function __TS__ClassExtends(this: void, target: LuaClass, base: LuaClass): void {
target.____super = base;
// Set base class as a metatable, because descriptors use `getmetatable` to get extended prototype
const staticMetatable: any = setmetatable({ __index: base }, base);
setmetatable(target, staticMetatable);
const baseMetatable = getmetatable(base);
if (baseMetatable) {
// Re-add metatable events defined by descriptors
if (typeof baseMetatable.__index === "function") staticMetatable.__index = baseMetatable.__index;
if (typeof baseMetatable.__newindex === "function") staticMetatable.__newindex = baseMetatable.__newindex;
}
setmetatable(target.prototype, base.prototype);
// Re-add metatable events defined by accessors with `__TS__SetDescriptor`
if (typeof base.prototype.__index === "function") target.prototype.__index = base.prototype.__index;
if (typeof base.prototype.__newindex === "function") target.prototype.__newindex = base.prototype.__newindex;
if (typeof base.prototype.__tostring === "function") target.prototype.__tostring = base.prototype.__tostring;
}