From 60b725499289c810eaf045ed22a1100402a0b8c9 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Mon, 29 Oct 2018 19:21:28 +0100 Subject: atdump() to treat certain values special --- advtrains/init.lua | 58 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'advtrains/init.lua') diff --git a/advtrains/init.lua b/advtrains/init.lua index fc7e423..3d420e6 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -58,6 +58,41 @@ end advtrains.modpath = minetest.get_modpath("advtrains") +--Advtrains dump (special treatment of pos and sigd) +function atdump(t, intend) + local str + if type(t)=="table" then + if t.x and t.y and t.z then + str=minetest.pos_to_string(t) + elseif t.p and t.s then -- interlocking sigd + str="S["..minetest.pos_to_string(t.p).."/"..t.s.."]" + else + str="{" + local intd = (intend or "") .. " " + for k,v in pairs(t) do + if type(k)~="string" or not string.match(k, "^path[_]?") then + -- do not print anything path-related + str = str .. "\n" .. intd .. atdump(k, intd) .. " = " ..atdump(v, intd) + end + end + str = str .. "\n" .. (intend or "") .. "}" + end + elseif type(t)=="boolean" then + if t then + str="true" + else + str="false" + end + elseif type(t)=="function" then + str="" + elseif type(t)=="userdata" then + str="" + else + str=""..t + end + return str +end + function advtrains.print_concat_table(a) local str="" local stra="" @@ -69,28 +104,7 @@ function advtrains.print_concat_table(a) else str=str..stra stra="" - if type(t)=="table" then - if t.x and t.y and t.z then - str=str..minetest.pos_to_string(t) - elseif t.p and t.s then -- interlocking sigd - str=str.."("..minetest.pos_to_string(t.p).."/"..t.s..")" - else - str=str..dump(t) - end - elseif type(t)=="boolean" then - if t then - str=str.."true" - else - str=str.."false" - end - elseif type(t)=="function" then - str=str.."" - elseif type(t)=="userdata" then - str=str.."" - else - str=str..t - end - str=str.." " + str=str..atdump(t).." " end end return str -- cgit v1.2.3