Created
March 8, 2015 19:25
-
-
Save SirUke/b822c2b6d105b40dce77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[--------------------------------------------------------- | |
Prints also a table to the console but a bit nicer | |
PrintTableDepth( Table toPrint, Number depth, Number max ) | |
toPrint: The table to be printed | |
depth: Amount of child-tables to open (-1 = inf, -1 <= depth) | |
max: Amount of elements to print per table (-1 = inf, -1 <= max) | |
-----------------------------------------------------------]] | |
local tcol = { | |
["string"] = Color(180,180,180), | |
["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), | |
["Entity"] = Color(70,255,160), | |
["Weapon"] = Color(70,255,160), | |
["Player"] = Color(70,255,160) | |
} | |
local bc = Color(120,255,70) --bracket color | |
local ec = Color(200,200,50) --equal sign color | |
local nc = Color(255,255,255) --normal color | |
local sc = Color(180,180,180) --shadow color | |
local cc = Color(50,150,50) --comment color | |
local tc = Color(70,200,255) --type function color | |
tostring2 = function(val,new) | |
local tp = type(val) | |
local tco = (tcol[tp] and new) and tcol[tp] or Color(200,200,200) | |
if tp == "string" then | |
MsgC(tco,"\""..string.Replace(val,"\n","\\n").."\"") | |
elseif tp == "Vector" then | |
MsgC(tc,"Vector",nc,"(",tco,val.x,nc,", ",tco,val.y,nc,", ",tco,val.z,nc,")") | |
elseif tp == "Angle" then | |
MsgC(tc,"Angle",nc,"(",tco,val.p,nc,", ",tco,val.y,nc,", ",tco,val.r,nc,")") | |
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,")") | |
else | |
MsgC(tc,"Color",nc,"(",tco,val.p,nc,", ",tco,val.y,nc,", ",tco,val.r,nc,")") | |
end | |
elseif tp == "function" then | |
MsgC(tco,"\""..tostring(val).."\"") | |
elseif tp == "Entity" or tp == "Weapon" or tp == "Player" then | |
local str = "" | |
for w in string.gmatch(tostring(val), "%[(%d+)%]") do | |
str = w | |
break | |
end | |
MsgC(tc,"Entity",nc,"(",tco,str,nc,")",cc,"/*"..tp.."*/") | |
else | |
MsgC(tco,tostring(val)) | |
end | |
if new then | |
MsgC(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.."[") tostring2(k,false) MsgC(sc,"] ",ec,"=",nc," ",bc,"{\n") | |
tbl_rec(v,depth,current,max) | |
MsgC(sc,indent,bc,"}",nc,",\n") | |
else | |
MsgC(sc,indent.."[") tostring2(k,false) MsgC(sc,"] ",ec,"=",nc," ") | |
tostring2(v,true) | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment