G migration mechanism (#1030)
This commit is contained in:
committed by
GitHub
parent
3d8912ca53
commit
97717d8d23
@@ -225,4 +225,60 @@ function M.canonical_path(path)
|
||||
return path
|
||||
end
|
||||
|
||||
-- Create empty sub-tables if not present
|
||||
-- @param tbl to create empty inside of
|
||||
-- @param sub dot separated string of sub-tables
|
||||
-- @return deepest sub-table
|
||||
function M.table_create_missing(tbl, sub)
|
||||
if tbl == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local t = tbl
|
||||
for s in string.gmatch(sub, "([^%.]+)%.*") do
|
||||
if t[s] == nil then
|
||||
t[s] = {}
|
||||
end
|
||||
t = t[s]
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
-- Serialise a table as a string
|
||||
-- @param val table to serialise
|
||||
-- @param name optional
|
||||
-- @param skipnewlines optional
|
||||
-- @param spaces to indent, for internal use
|
||||
function M.table_tostring(val, name, skipnewlines, depth)
|
||||
skipnewlines = skipnewlines or false
|
||||
depth = depth or 0
|
||||
|
||||
local tmp = string.rep(" ", depth)
|
||||
|
||||
if name then
|
||||
tmp = tmp .. name .. " = "
|
||||
end
|
||||
|
||||
if type(val) == "table" then
|
||||
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
|
||||
|
||||
for k, v in pairs(val) do
|
||||
tmp = tmp .. M.table_tostring(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
|
||||
end
|
||||
|
||||
tmp = tmp .. string.rep(" ", depth) .. "}"
|
||||
elseif type(val) == "number" then
|
||||
tmp = tmp .. tostring(val)
|
||||
elseif type(val) == "string" then
|
||||
tmp = tmp .. string.format("%q", val)
|
||||
elseif type(val) == "boolean" then
|
||||
tmp = tmp .. tostring(val)
|
||||
else
|
||||
tmp = tmp .. "\"[" .. type(val) .. "]\""
|
||||
end
|
||||
|
||||
return tmp
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user