Anonymous

Module:CommonFunctions: Difference between revisions

From Elwiki
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local inspect = require('Module:Inspect').inspect
-- in Array
-- in Array
function inArray(key, array)
function inArray(key, array)
Line 187: Line 189:
     end
     end
     return formatted
     return formatted
end
function table.deep_copy(original)
    local copy = {}
    for k, v in pairs(original) do
        if type(v) == "table" then
            copy[k] = table.deep_copy(v)
        else
            copy[k] = v
        end
    end
    return setmetatable(copy, getmetatable(original))
end
function dump(tbl)
    local ret = {}
    for k, v in pairs(tbl) do
        table.insert(ret, k .. ': ' .. inspect(v))
    end
    return frame:preprocess(table.concat(ret, "<br/>"))
end
function inspect_dump(tbl, frame)
    return frame:preprocess("<pre><nowiki>" .. inspect(tbl) .. "</nowiki></pre>")
end
end