-- Library: dumptable -- Version: 0.2 -- Author: reyalp (at) gmail.com -- Description: -- Quick and dirty recursive table display. -- Shows the type and value of all keys and values of a table. -- Subtables are displayed indented -- -- Arguments: -- t table to dump -- maxpdepth optional maximum number of tables to recurse, defaults to 10 -- indent optional indent level, increases for every table recursed -- -- WARNINGS: -- Running this on very large tables (_G for example) may kill your server. -- Does not detect looping structures. -- -- Changelog: -- 0.2 -- detect tables that refer to themselves -- use et.G_Printf -- 0.1 -- initial version function DumpTable(t,maxdepth,indent) if type(t) ~= "table" then error('expected table') end if not maxdepth then maxdepth = 10 elseif maxdepth == 0 then et.G_Print("<<>>\n") return end if not indent then indent = 0 end local indents = string.rep(" ",indent) for k,v in pairs(t) do et.G_Printf("%s(%s)[%s]->(%s)[%s]\n",indents,type(k),tostring(k),type(v),tostring(v)) if type(v) == "table" then -- detect tables that refer to themselves -- more comlicated structures will be detected caught by maxdepth if v == t then et.G_Printf("<<<[%s]->current table>>>\n",tostring(k)) else DumpTable(v,maxdepth - 1,indent +1) end end end end