Created
March 27, 2015 05:27
-
-
Save ahappyforest/ff92868e3ce2f80bd6c7 to your computer and use it in GitHub Desktop.
version 2 for print_r
This file contains hidden or 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
function print_r2(data, depth) | |
local depth = depth or 3 | |
local cstring = ""; | |
local top_flag = true | |
local function table_len(t) | |
local i = 0 | |
for k, v in pairs(t) do | |
i = i + 1 | |
end | |
return i | |
end | |
local function tableprint(data,cstring, local_depth) | |
if data == nil then | |
local_print("core.print data is nil"); | |
end | |
local cs = cstring .. " "; | |
if top_flag then | |
local_print(cstring .."{"); | |
top_flag = false | |
end | |
if(type(data)=="table") then | |
for k, v in pairs(data) do | |
if type(v) ~= "table" then | |
--if type(v) == "function" then | |
--local_print(cs..tostring(k).." = Funtion:"); | |
--else | |
local_print(cs..tostring(k).." = "..tostring(v)); | |
--end | |
elseif table_len(v) == 0 then | |
local_print(cs..tostring(k).." = ".."{}") | |
elseif local_depth < depth then | |
local_print(cs..tostring(k).." = {"); | |
tableprint(v,cs,local_depth+1); | |
else | |
local_print(cs..tostring(k).." = ".."{*}") | |
end | |
end | |
else | |
local_print(cs..tostring(data)); | |
end | |
local_print(cstring .."}"); | |
end | |
tableprint(data,cstring,0); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment