Skip to content

Commit 4f13e25

Browse files
committed
Isolate require cache across plugins, recursion check
1 parent 0cab1b9 commit 4f13e25

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

plugins/std/src/shared/require.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
local unpack = unpack
2-
local includeCache = {}
2+
3+
---@type table<lightuserdata, table<string, table | true>>
4+
local cache = {}
35

46
function Autorun.require(path)
5-
if includeCache[path] then
6-
return unpack(includeCache[path])
7+
cache[Autorun.PLUGIN] = cache[Autorun.PLUGIN] or {}
8+
local localCache = cache[Autorun.PLUGIN]
9+
10+
if localCache[path] == true then
11+
error("Circular dependency detected for path: " .. path)
12+
elseif localCache[path] then
13+
return unpack(cache[path])
714
end
815

16+
localCache[path] = true
917
local outputs = { Autorun.include(path) }
10-
includeCache[path] = outputs
18+
localCache[path] = outputs
1119

1220
return unpack(outputs)
1321
end

0 commit comments

Comments
 (0)