From 9bd53b7e75341feb20d0dacc3c4c29aedec1bc9b Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 22 Mar 2022 22:42:19 -0400 Subject: [PATCH] Improve dumpTable function --- script.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/script.lua b/script.lua index ee3e04f..6e582dd 100644 --- a/script.lua +++ b/script.lua @@ -9,16 +9,21 @@ TEXTURE_HEIGHT = 128 --- Create a string representation of a table --- @param o table function dumpTable(o) - if type(o) == 'table' then - local s = '{ ' - for k,v in pairs(o) do - if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. dumpTable(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end + if type(o) == 'table' then + local s = '{ ' + local first_loop=true + for k,v in pairs(o) do + if not first_loop then + s = s .. ', ' + end + first_loop=false + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. dumpTable(v) + end + return s .. '} ' + else + return tostring(o) + end end ---@param uv table