Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PrintTableDepth by Uke
- local tcol = {
- ["string"] = Color(130,130,130),
- ["table"] = Color(160,50,50),
- ["number"] = Color(255,130,0),
- ["Vector"] = Color(255,130,0),
- ["Angle"] = Color(255,130,0),
- ["Color"] = Color(255,130,0),
- ["boolean"] = Color(0,255,160),
- ["function"] = Color(20,130,180)
- }
- local bc = Color(120,255,70)
- local ec = Color(200,200,50)
- local nc = Color(255,255,255)
- local sc = Color(180,180,180)
- local cc = Color(50,150,50)
- local tc = Color(70,200,255)
- oldtostring = tostring
- tostring2 = function(val)
- local tp = type(val)
- local tco = tcol[tp]
- if tp == "string" then
- MsgC(tco,"\""..string.Replace(val,"\n","\\n").."\"",nc,",\n")
- elseif tp == "Vector" then
- MsgC(tc,"Vector",nc,"(",tco,val.x,nc,", ",tco,val.y,nc,", ",tco,val.z,nc,"),\n")
- elseif tp == "Angle" then
- MsgC(tc,"Angle",nc,"(",tco,val.p,nc,", ",tco,val.y,nc,", ",tco,val.r,nc,"),\n")
- elseif tp == "Color" then
- if val.a != nil then
- MsgC(tc,"Color",nc,"(",tco,val.p,nc,", ",tco,val.y,nc,", ",tco,val.r,nc,", ",tco,val.a,nc,"),\n")
- else
- MsgC(tc,"Color",nc,"(",tco,val.p,nc,", ",tco,val.y,nc,", ",tco,val.r,nc,"),\n")
- end
- elseif tp == "function" then
- MsgC(tco,"\""..oldtostring(val).."\"",nc,",\n")
- else
- MsgC(tco,oldtostring(val),nc,",\n")
- end
- end
- local function tbl_rec(tbl,depth,current,max)
- current = current + 1
- local indent = string.rep( "\t", current )
- if current <= depth or depth == -1 then
- local c = 0
- local c2 = 0
- for k,v in pairs(tbl) do
- c = c + 1
- if c <= max or max == -1 then
- if type(v) == "table" then
- MsgC(sc,indent.."[\"",nc,k,sc,"\"] ",ec,"=",nc," ",bc,"{\n")
- tbl_rec(v,depth,current,max)
- MsgC(sc,indent,bc,"}",nc,",\n")
- else
- MsgC(sc,indent.."[\"",nc,k,sc,"\"] ",ec,"=",nc," ")
- tostring2(v)
- end
- else
- c2 = c2 + 1
- end
- end
- if c2 > 0 then
- if c2 != 1 then
- MsgC(cc,indent.."/* ",c2," more elements. (amount restriced)*/\n")
- else
- MsgC(cc,indent.."/* ",c2," more element. (amount restriced)*/\n")
- end
- end
- else
- local c = 0
- for k,v in pairs(tbl) do
- c = c + 1
- end
- if c != 1 then
- MsgC(cc,indent.."/* ",c," elements. (depth restriced)*/\n")
- else
- MsgC(cc,indent.."/* ",c," element. (depth restriced)*/\n")
- end
- end
- end
- function PrintTableDepth(tab,depth,max)
- if tab == nil or type(tab) != "table" or depth == nil or type(depth) != "number" or depth < -1 or type(max) != "number" or max < -1 or max == nil then MsgC(Color(255,0,0),"\n\nManual:",Color(200,255,255),"\nPrintTableDepth( Table toPrint, Number depth, Number max )\ntoPrint: \tThe table to be printed\ndepth: \t\tAmount of child-tables to open (-1 = inf, -1 <= depth)\nmax: \t\tAmount of elements to print per table (-1 = inf, -1 <= max)\n\n") return end
- MsgC(tc,"ROOT ",ec,"=",nc," ",bc,"{\n")
- tbl_rec(tab,depth,0,max)
- MsgC(bc,"}\n\n")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement