A = {
B = {
C = {},
D = {},
},
E = {
F = {
G = {}
}
},
H = {}
}
function f(root, find)
-- iterate over all child values
for k, v in pairs(root) do
if k == find then
-- found the match
return({find})
else
-- no match, search the children
tmp = f(root[k], find)
if tmp ~= nil then
table.insert(tmp, 1, k)
return tmp
end
end
end
end
print(table.concat(f(A, "G"), " "))
( , A), , :
r = {A = {
B = {
C = {},
D = {},
},
E = {
F = {
G = {}
}
},
H = {}
}
}
f (r, "G" ) .