diff options
Diffstat (limited to 'script/vm/vm.lua')
-rw-r--r-- | script/vm/vm.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/script/vm/vm.lua b/script/vm/vm.lua index 0e7f3176..a9c788fc 100644 --- a/script/vm/vm.lua +++ b/script/vm/vm.lua @@ -10,6 +10,8 @@ local log = log local xpcall = xpcall local mathHuge = math.huge +local weakValueMT = { __mode = 'v' } + _ENV = nil ---@class vm @@ -104,7 +106,7 @@ function m.mergeResults(a, b) return a end -m.cacheTracker = setmetatable({}, { __mode = 'kv' }) +m.cacheTracker = setmetatable({}, weakValueMT) function m.flushCache() if m.cache then @@ -113,17 +115,17 @@ function m.flushCache() m.cacheVersion = files.globalVersion m.cache = {} m.cacheActiveTime = mathHuge - m.locked = setmetatable({}, { __mode = 'k' }) + m.locked = setmetatable({}, weakValueMT) m.cacheTracker[m.cache] = true end -function m.getCache(name) +function m.getCache(name, weak) if m.cacheVersion ~= files.globalVersion then m.flushCache() end m.cacheActiveTime = timer.clock() if not m.cache[name] then - m.cache[name] = {} + m.cache[name] = weak and setmetatable({}, weakValueMT) or {} end return m.cache[name] end |