From a887d3f193fc48c2a9c93d3032bdd6c92e4ba15f Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 7 Sep 2019 01:29:11 +1000 Subject: Switch printTable to dumpTable. --- mirror-checker.lua | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'mirror-checker.lua') diff --git a/mirror-checker.lua b/mirror-checker.lua index 9dd93bb..0e8567e 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -79,34 +79,38 @@ local http = require 'socket.http' local url = require 'socket.url' --- Use this to print a table. -printTable = function (table, space, name) - if "" == space then print(space .. name .. " =") else print(space .. "[" .. name .. "] =") end - print(space .. "{") - printTableSub(table, space .. " ") - if "" == space then print(space .. "}") else print(space .. "},") end +-- Use this to dump a table to a string. +dumpTable = function (table, space, name) + local r = "" + if "" == space then r = r .. space .. name .. " =\n" else r = r .. space .. "[" .. name .. "] =\n" end + r = r .. space .. "{\n" + r = r .. dumpTableSub(table, space .. " ") + if "" == space then r = r .. space .. "}\n" else r = r .. space .. "},\n" end + return r end -printTableSub = function (table, space) +dumpTableSub = function (table, space) + local r = "" for k, v in pairs(table) do if type(k) == "string" then k = '"' .. k .. '"' end if type(v) == "table" then - printTable(v, space, k) + r = r .. dumpTable(v, space, k) elseif type(v) == "string" then - print(space .. "[" .. k .. "] = '" .. v .. "';") + r = r .. space .. "[" .. k .. "] = '" .. v .. "';\n" elseif type(v) == "function" then - print(space .. "[" .. k .. "] = function ();") + r = r .. space .. "[" .. k .. "] = function ();\n" elseif type(v) == "userdata" then - print(space .. "userdata " .. "[" .. k .. "];") + r = r .. space .. "userdata " .. "[" .. k .. "];\n" elseif type(v) == "boolean" then if (v) then - print(space .. "boolean " .. "[" .. k .. "] = true;") + r = r .. space .. "[" .. k .. "] = true;\n" else - print(space .. "boolean " .. "[" .. k .. "] = false;") + r = r .. space .. "[" .. k .. "] = false;\n" end else - print(space .. "[" .. k .. "] = " .. v .. ";") + r = r .. space .. "[" .. k .. "] = " .. v .. ";\n" end end + return r end local log = function(v, t, s) @@ -442,7 +446,7 @@ if 0 ~= #args then end end ---printTable(options.tests.value, "", "tests") +--print(dumpTable(options.tests.value, "", "tests")) execute("mkdir -p results") -- cgit v1.1