Skip to content

Commit 5505d42

Browse files
API.copy_table now properly copies read-only tables
1 parent 5b25e8d commit 5505d42

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

file-browser.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,15 +697,14 @@ end
697697
--uses a structured clone algorithm to maintain cyclic references
698698
local function copy_table_recursive(t, references, depth)
699699
if type(t) ~= "table" or depth == 0 then return t end
700-
if references[t] then return references[t] end
701700

702701
--bypasses the proxy protecting read-only tables
703702
local mt = getmetatable(t)
704-
local original_t
705-
if mt and mt.__newindex == newindex then original_t = mt.__index end
703+
if mt and mt.__newindex == readonly_newindex then t = mt.mutable end
704+
if references[t] then return references[t] end
706705

707706
local copy = setmetatable({}, { __original = t })
708-
references[original_t or t] = copy
707+
references[t] = copy
709708

710709
for key, value in pairs(t) do
711710
key = copy_table_recursive(key, references, depth - 1)

0 commit comments

Comments
 (0)