summaryrefslogtreecommitdiff
path: root/logutil.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-10-18 15:27:55 +0200
committerorwell96 <orwell@bleipb.de>2020-10-18 15:41:08 +0200
commit7000c5220d9ce8864e028d3b035d86040e7de7aa (patch)
treefae8c7d0d6e83dfa10e41d2c7fd88269469f4085 /logutil.lua
downloadcellworld-7000c5220d9ce8864e028d3b035d86040e7de7aa.tar.gz
cellworld-7000c5220d9ce8864e028d3b035d86040e7de7aa.tar.bz2
cellworld-7000c5220d9ce8864e028d3b035d86040e7de7aa.zip
Initial working stateHEADmaster
Diffstat (limited to 'logutil.lua')
-rw-r--r--logutil.lua48
1 files changed, 48 insertions, 0 deletions
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="<function>"
+ elseif type(t)=="userdata" then
+ str="<userdata>"
+ 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