Browse Source

Renamed file.

Marcos Kirsch 9 years ago
parent
commit
ba390bb855
1 changed files with 32 additions and 0 deletions
  1. 32 0
      TablePrinter.lua

+ 32 - 0
TablePrinter.lua

@@ -0,0 +1,32 @@
+-- Print anything - including nested tables
+-- Based on but modified from:
+-- http://lua-users.org/wiki/TableSerialization
+module("printTable", package.seeall)
+
+function printTable.printTable (tt, indent, done)
+   done = done or {}
+   indent = indent or 0
+   if tt == nil then
+      print("nil\n")
+   else
+      if type(tt) == "table" then
+         for key, value in pairs (tt) do
+            print(string.rep (" ", indent)) -- indent it
+            if type (value) == "table" and not done [value] then
+               done [value] = true
+               print(string.format("[%s] => table\n", tostring (key)));
+               print(string.rep (" ", indent+4)) -- indent it
+               print("(\n");
+               table_print (value, indent + 7, done)
+               print(string.rep (" ", indent+4)) -- indent it
+               print(")\n");
+            else
+               print(string.format("[%s] => %s\n",
+               tostring (key), tostring(value)))
+            end
+         end
+      else
+         print(tt .. "\n")
+      end
+   end
+end