From 56b51a66cb6f9cbcc008a85cd79c71959efa3ccb Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 25 Jun 2019 21:47:13 +1000 Subject: Modify printTable to look more like an actual table definition. --- mirror-checker.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mirror-checker.lua b/mirror-checker.lua index 4ebaecb..c9dd870 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -74,29 +74,30 @@ local url = require 'socket.url' -- Use this to print a table. printTable = function (table, space, name) - print(space .. name .. ": ") + if "" == space then print(space .. name .. " =") else print(space .. "[" .. name .. "] =") end print(space .. "{") printTableSub(table, space .. " ") - print(space .. "}") + if "" == space then print(space .. "}") else print(space .. "},") end end printTableSub = function (table, space) for k, v in pairs(table) do + if type(k) == "string" then k = '"' .. k .. '"' end if type(v) == "table" then printTable(v, space, k) elseif type(v) == "string" then - print(space .. k .. ': "' .. v .. '";') + print(space .. "[" .. k .. "] = '" .. v .. "';") elseif type(v) == "function" then - print(space .. "function " .. k .. "();") + print(space .. "[" .. k .. "] = function ();") elseif type(v) == "userdata" then - print(space .. "userdata " .. k .. ";") + print(space .. "userdata " .. "[" .. k .. "];") elseif type(v) == "boolean" then if (v) then - print(space .. "boolean " .. k .. " TRUE ;") + print(space .. "boolean " .. "[" .. k .. "] = true;") else - print(space .. "boolean " .. k .. " FALSE ;") + print(space .. "boolean " .. "[" .. k .. "] = false;") end else - print(space .. k .. ": " .. v .. ";") + print(space .. "[" .. k .. "] = " .. v .. ";") end end end -- cgit v1.1