Icon representing a recipe

Recipe: CG303 Table Show Deep V1.000

created by Crashguard303

Profile


Name
CG303 Table Show Deep V1.000
ID
45960
Shared with
Public
Parent
None
Children
None
Created on
April 24, 2013 at 22:46 PM UTC
Updated on
April 24, 2013 at 22:46 PM UTC
Description

Useful for debugging.
Shows the 'complete' content of a polymorphic table (means: the table can have various elements & subtables with various elements & subtables...)

Best for


Code


function list_show_deep(list,text) -- full key and value as string - advanced -- indexing: pairs if text==nil then text=tostring(list) end -- if text local k,v for k,v in pairs(list) do local ktext if type(k)=="number" then ktext= text..'['..tostring(k)..']' else ktext= text..'.'..tostring(k) end -- if type(k) if type(v)=="table" then list_show_deep(v,ktext) else local vtext if (type(v)=="number") or (type(v)=="boolean") then vtext= tostring(v) else vtext= '\"'..tostring(v)..'\"' end -- if type(v) print(ktext..'='..vtext) end -- if type(v) end -- for k end -- function list_show_deep -- test table with various depths to print out: test={ title="root table"; "1"; { title="first subtable"; "2.1"; "2.2" }; { title="second subtable"; { title="first subtable of second subtable"; "3.1.1"; "3.1.2" }; { title="second subtable of second subtable"; "3.2.1"; "3.2.2" }; } } list_show_deep(test,"test")

Comments