@@ -374,6 +374,7 @@ API.coroutine = {}
374374local ABORT_ERROR = {
375375 msg = " browser is no longer waiting for list - aborting parse"
376376}
377+ local newindex = function (t , k , v ) error ((" attempted to assign `%s` to key `%s` in read-only %s" ):format (v , k , t ), 2 ) end
377378
378379-- implements table.pack if on lua 5.1
379380if not table.pack then
@@ -685,8 +686,13 @@ local function copy_table_recursive(t, references, depth)
685686 if type (t ) ~= " table" or depth == 0 then return t end
686687 if references [t ] then return references [t ] end
687688
689+ -- bypasses the proxy protecting read-only tables
690+ local mt = getmetatable (t )
691+ local original_t
692+ if mt and mt .__newindex == newindex then original_t = mt .__index end
693+
688694 local copy = setmetatable ({}, { __original = t })
689- references [t ] = copy
695+ references [original_t or t ] = copy
690696
691697 for key , value in pairs (t ) do
692698 key = copy_table_recursive (key , references , depth - 1 )
704710-- handles the read-only table logic
705711do
706712 local references = setmetatable ({}, { __mode = ' k' })
707- local newindex = function (t , k , v ) error ((" attempted to assign `%s` to key `%s` in read-only %s" ):format (v , k , t )) end
708713
709714 -- returns a read-only reference to the table t
710715 function API .read_only (t )
0 commit comments