How would I go about unpacking "GetLogHistory"?
print(unpack(game.LogService:GetLogHistory()))
--returns more tables
--How would I manage to unpack all tables until there are no more?
How would I go about unpacking "GetLogHistory"?
print(unpack(game.LogService:GetLogHistory()))
--returns more tables
--How would I manage to unpack all tables until there are no more?
I am not familiar with this method, so I'm going to make a guess at what you want:
You would want to turn, for instance,
{ { 1, 2, {3} } , { {4 , 5} , { { 6 , 7 } } } , 8 , 9 }
into
1, 2, 3, 4, 5, 6, 7, 8, 9
I don't believe there is any "inline" solution to this, but making a function which accomplishes it involving some copying to a new table is easy.
function flatten(tab,toward)
-- Takes all non table values from
-- `tab` and adds them to the end
-- of `toward`.
-- Table values are recursively
-- 'flattened' into toward as well
if type(tab) == type({}) then
-- A table:
-- Recursively search
-- Set up basket to hold all values:
toward = toward or {};
for i = 1, #tab do
flatten(tab[i], toward);
end
return toward;
else
-- Not a table:
-- Insert to `toward`
table.insert(toward, tab);
end
end
function unpackRecursive(tab)
-- Unpack result of flattening tab
-- to get one uninterrupted list of non table
-- elements from the tree of tables, `tab`
return unpack(flatten(tab));
end
This discussion is preserved as it was. New answers, comments, and votes are closed.