mirror of
https://github.com/Insality/druid
synced 2025-11-26 10:50:54 +01:00
Add Druid logger
This commit is contained in:
@@ -404,24 +404,44 @@ function M.is_multitouch_supported()
|
||||
end
|
||||
|
||||
|
||||
---Simple table to one-line string converter
|
||||
---Converts table to one-line string
|
||||
---@param t table
|
||||
---@return string
|
||||
function M.table_to_string(t)
|
||||
if not t then
|
||||
return ""
|
||||
---@param depth number?
|
||||
---@param result string|nil Internal parameter
|
||||
---@return string, boolean result String representation of table, Is max string length reached
|
||||
function M.table_to_string(t, depth, result)
|
||||
if type(t) ~= "table" then
|
||||
return tostring(t) or "", false
|
||||
end
|
||||
|
||||
local result = "{"
|
||||
depth = depth or 0
|
||||
result = result or "{"
|
||||
|
||||
for key, value in pairs(t) do
|
||||
if #result > 1 then
|
||||
result = result .. ","
|
||||
result = result .. ", "
|
||||
end
|
||||
|
||||
if type(value) == "table" then
|
||||
if depth == 0 then
|
||||
local table_len = 0
|
||||
for _ in pairs(value) do
|
||||
table_len = table_len + 1
|
||||
end
|
||||
result = result .. key .. ": {... #" .. table_len .. "}"
|
||||
else
|
||||
local convert_result, is_limit = M.table_to_string(value, depth - 1, "")
|
||||
result = result .. key .. ": {" .. convert_result
|
||||
if is_limit then
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
result = result .. key .. ": " .. tostring(value)
|
||||
end
|
||||
result = result .. key .. ": " .. value
|
||||
end
|
||||
|
||||
return result .. "}"
|
||||
return result .. "}", false
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user