Skip to content

Commit 0d2ed20

Browse files
committed
Don't remove metatable in adapter to make re-registering more stable
1 parent 73a5020 commit 0d2ed20

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

game/scripts/vscripts/lib/dota_ts_adapter.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ function clearTable(table: object) {
109109
for (const key in table) {
110110
delete (table as any)[key];
111111
}
112-
113-
// Remove metatable added by ExtendInstance
114-
// https://github.com/SteamDatabase/GameTracking-Dota2/blob/7edcaa294bdcf493df0846f8bbcd4d47a5c3bd57/game/core/scripts/vscripts/init.lua#L195
115-
setmetatable(table, undefined);
116112
}
117113

118114
function getFileScope(): [any, string] {
@@ -131,7 +127,9 @@ function toDotaClassInstance(instance: any, table: new () => any) {
131127
let { prototype } = table;
132128
while (prototype) {
133129
for (const key in prototype) {
134-
if (instance[key] == null) {
130+
// Using hasOwnProperty to ignore methods from metatable added by ExtendInstance
131+
// https://github.com/SteamDatabase/GameTracking-Dota2/blob/7edcaa294bdcf493df0846f8bbcd4d47a5c3bd57/game/core/scripts/vscripts/init.lua#L195
132+
if (!instance.hasOwnProperty(key)) {
135133
instance[key] = prototype[key];
136134
}
137135
}

0 commit comments

Comments
 (0)