diff --git a/love/mike/lib/testing.lua b/love/mike/lib/testing.lua new file mode 100644 index 0000000..17d1d95 --- /dev/null +++ b/love/mike/lib/testing.lua @@ -0,0 +1,51 @@ +require "io" + +t = {} +t.jerk = "dick" +t.saint = "Brit" +t.num = 92 +t.multi = {} +t.multi.cat = "mu mu" +t.multi.dog = "iz" +t.multi.number = 53 + +function printf (s, ...) + return io.write(s:format(...)) +end + +function print_table(tbl, only_once) + if only_once == nil then + printf("{") + end + for key,value in pairs(tbl) do + if type(value) == "table" then + printf("%s = {\n",key) + print_table(value, true) + printf("}\n") + end + if type (value) ~= "table" then + if type(value) == "string" then + printf("%s = \"%s\"\n", key, value) + else + printf("%s = %d\n", key, value) + end + end + end + if only_once == nil then + printf("}\n") + end +end + +function tablelength(tbl, count) + local count = count or 0 + + for key, value in pairs(tbl) do + if type(value) == "table" then + count = tablelength(value, count) + end + count = count + 1 + end + return count +end + +print_table(t)