mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 01:03:46 +01:00
Lua log file: Fix infinite recursion
This commit is contained in:
parent
257b9bc4d7
commit
ff8a4f6f76
@ -87,6 +87,10 @@ function lua_log_file:_dump(value, is_key)
|
|||||||
reference = self.reference_count + 1
|
reference = self.reference_count + 1
|
||||||
local key = "R[" .. reference .."]"
|
local key = "R[" .. reference .."]"
|
||||||
local formatted
|
local formatted
|
||||||
|
local function create_reference()
|
||||||
|
self.reference_count = reference
|
||||||
|
self.references[value] = reference
|
||||||
|
end
|
||||||
if _type == "string" then
|
if _type == "string" then
|
||||||
if is_key and value:len() <= key:len() and value:match"[%a_][%a%d_]*" then
|
if is_key and value:len() <= key:len() and value:match"[%a_][%a%d_]*" then
|
||||||
-- Short key
|
-- Short key
|
||||||
@ -97,7 +101,11 @@ function lua_log_file:_dump(value, is_key)
|
|||||||
-- Short string
|
-- Short string
|
||||||
return formatted
|
return formatted
|
||||||
end
|
end
|
||||||
|
-- Use reference
|
||||||
|
create_reference()
|
||||||
elseif _type == "table" then
|
elseif _type == "table" then
|
||||||
|
-- Tables always need a reference before they are traversed to prevent infinite recursion
|
||||||
|
create_reference()
|
||||||
local entries = {}
|
local entries = {}
|
||||||
for _, value in ipairs(value) do
|
for _, value in ipairs(value) do
|
||||||
table.insert(entries, self:_dump(value))
|
table.insert(entries, self:_dump(value))
|
||||||
@ -113,8 +121,6 @@ function lua_log_file:_dump(value, is_key)
|
|||||||
else
|
else
|
||||||
error("unsupported type: " .. _type)
|
error("unsupported type: " .. _type)
|
||||||
end
|
end
|
||||||
self.reference_count = reference
|
|
||||||
self.references[value] = reference
|
|
||||||
self:log(key .. "=" .. formatted)
|
self:log(key .. "=" .. formatted)
|
||||||
return key
|
return key
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user