From ffeed6eacdb8ad69c7b5f2294c0c12b402de89d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 31 Jan 2021 01:37:10 +0800 Subject: safe pairs --- script/vm/getGlobals.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'script') diff --git a/script/vm/getGlobals.lua b/script/vm/getGlobals.lua index e1fd0e7a..842db4c3 100644 --- a/script/vm/getGlobals.lua +++ b/script/vm/getGlobals.lua @@ -194,14 +194,20 @@ local function checkNeedUpdate() local getGlobalCache = ws.getCache 'getGlobals' local getGlobalSetsCache = ws.getCache 'getGlobalSets' local needUpdateGlobals = ws.getCache 'needUpdateGlobals' + local uris = {} for uri in pairs(needUpdateGlobals) do - needUpdateGlobals[uri] = nil - if files.exists(uri) then - for name in pairs(getGlobalsOfFile(uri)) do - getGlobalCache[name] = nil - end - for name in pairs(getGlobalSetsOfFile(uri)) do - getGlobalSetsCache[name] = nil + uris[#uris+1] = uri + end + for _, uri in ipairs(uris) do + if needUpdateGlobals[uri] then + needUpdateGlobals[uri] = nil + if files.exists(uri) then + for name in pairs(getGlobalsOfFile(uri)) do + getGlobalCache[name] = nil + end + for name in pairs(getGlobalSetsOfFile(uri)) do + getGlobalSetsCache[name] = nil + end end end end -- cgit v1.2.3