mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 10:43:43 +01:00
Lua log file: Fix handling of circular tables
This commit is contained in:
parent
abced343d8
commit
cc88228d25
@ -106,7 +106,6 @@ function lua_log_file:_dump(value, is_key)
|
|||||||
end
|
end
|
||||||
reference = self.reference_count + 1
|
reference = self.reference_count + 1
|
||||||
local key = "R[" .. reference .."]"
|
local key = "R[" .. reference .."]"
|
||||||
local formatted
|
|
||||||
local function create_reference()
|
local function create_reference()
|
||||||
self.reference_count = reference
|
self.reference_count = reference
|
||||||
self.references[value] = reference
|
self.references[value] = reference
|
||||||
@ -117,32 +116,29 @@ function lua_log_file:_dump(value, is_key)
|
|||||||
-- Short key
|
-- Short key
|
||||||
return value, true
|
return value, true
|
||||||
end
|
end
|
||||||
formatted = ("%q"):format(value)
|
local formatted = ("%q"):format(value)
|
||||||
if (not reference_strings) or formatted:len() <= key:len() then
|
if (not reference_strings) or formatted:len() <= key:len() then
|
||||||
-- Short string
|
-- Short string
|
||||||
return formatted
|
return formatted
|
||||||
end
|
end
|
||||||
-- Use reference
|
-- Use reference
|
||||||
create_reference()
|
create_reference()
|
||||||
|
self:log(key .. "=" .. formatted)
|
||||||
elseif _type == "table" then
|
elseif _type == "table" then
|
||||||
-- Tables always need a reference before they are traversed to prevent infinite recursion
|
-- Tables always need a reference before they are traversed to prevent infinite recursion
|
||||||
create_reference()
|
create_reference()
|
||||||
local entries = {}
|
-- TODO traverse tables to determine whether this is actually needed
|
||||||
for _, value in ipairs(value) do
|
self:log(key .. "={}")
|
||||||
table.insert(entries, self:_dump(value))
|
|
||||||
end
|
|
||||||
local tablelen = #value
|
local tablelen = #value
|
||||||
for key, value in pairs(value) do
|
for k, v in pairs(value) do
|
||||||
if type(key) ~= "number" or key % 1 ~= 0 or key < 1 or key > tablelen then
|
if type(k) ~= "number" or k % 1 ~= 0 or k < 1 or k > tablelen then
|
||||||
local dumped, short = self:_dump(key, true)
|
local dumped, short = self:_dump(k, true)
|
||||||
table.insert(entries, (short and dumped or ("[" .. dumped .. "]")) .. "=" .. self:_dump(value))
|
self:log(key .. (short and ("." .. dumped) or ("[" .. dumped .. "]")) .. "=" .. self:_dump(v))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
formatted = "{" .. table.concat(entries, ";") .. "}"
|
|
||||||
else
|
else
|
||||||
error("unsupported type: " .. _type)
|
error("unsupported type: " .. _type)
|
||||||
end
|
end
|
||||||
self:log(key .. "=" .. formatted)
|
|
||||||
return key
|
return key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user