From 55f5ee6eb5c152e34dcd41131e477dacacb4bd79 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Wed, 15 May 2019 12:05:54 +0800 Subject: [PATCH] battlemain --- luafight/BattleMain.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/luafight/BattleMain.lua b/luafight/BattleMain.lua index f857802da..32a371d33 100644 --- a/luafight/BattleMain.lua +++ b/luafight/BattleMain.lua @@ -66,27 +66,41 @@ end local function PrintTable(tb) local indent_str = "{" + local count = 0 + for k,v in pairs(tb) do + count = count + 1 + end for k=1, #tb do local v = tb[k] if type(v) == "table" then indent_str = indent_str .. PrintTable(v) else - indent_str = indent_str .. tostring(v).."," + indent_str = indent_str .. tostring(v) + end + if k < count then + indent_str = indent_str.."," end end - for k,v in newPairs(tb) do + + local index = 0 + for k,v in pairs(tb) do + index = index + 1 if type(k) ~= "number" then if type(v) == "table" then indent_str = string.format("%s%s=%s", indent_str, tostring(k), PrintTable(v)) else - indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v)..",") + indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v)) + end + if index < count then + indent_str = indent_str .. "," end end end - indent_str = indent_str .. "}," + indent_str = indent_str .. "}" return indent_str end + --捕获异常,并输出错误日志 local function error( err ) local time = string.format("%d-%d-%d-%d-%d-%d",