From 7000c5220d9ce8864e028d3b035d86040e7de7aa Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sun, 18 Oct 2020 15:27:55 +0200 Subject: Initial working state --- logutil.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 logutil.lua (limited to 'logutil.lua') diff --git a/logutil.lua b/logutil.lua new file mode 100644 index 0000000..5b01ea2 --- /dev/null +++ b/logutil.lua @@ -0,0 +1,48 @@ +-- Logutils - originally part of advtrains + +local function dump(t, intend) + local str + if not t then + str = "nil" + elseif type(t)=="table" then + if t.x and t.y and t.z then + str=minetest.pos_to_string(t) + else + str="{" + local intd = (intend or "") .. " " + for k,v in pairs(t) do + str = str .. "\n" .. intd .. dump(k, intd) .. " = " ..dump(v, intd) + 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 + +local function print_concat_table(tab) + -- go through table and find max entry + local maxe = 0 + for k, _ in pairs(tab) do + maxe = math.max(maxe, k) + end + + local t = {} + for i=1,maxe do + t[i] = dump(tab[i]) + end + return table.concat(t, " ") +end + +return print_concat_table, dump -- cgit v1.2.3