I want to print this table using recursion and not by using for loop. I am trying to avoid repeating code.
local t = {x=0, y=5, other={10,10,10,11}}
function DeepPrint (t)
local request_headers_all = ""
for k, v in pairs(t) do
if type(v) == "table" then
for k1, v1 in pairs(v) do
local rowtext = ""
rowtext = string.format("[%s %s] ",k, v1)
request_headers_all = request_headers_all .. rowtext
end
else
local rowtext = ""
rowtext = string.format("[%s %s] ", k, v)
request_headers_all = request_headers_all .. rowtext
end
end
return request_headers_all
end
print(DeepPrint (t))
Expected output (order doesn't matter):
[y 5] [x 0] [other 10] [other 10] [other 10] [other 11]