summaryrefslogtreecommitdiff
path: root/lualibs-table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualibs-table.lua')
-rw-r--r--lualibs-table.lua9
1 files changed, 3 insertions, 6 deletions
diff --git a/lualibs-table.lua b/lualibs-table.lua
index 640bbbb..e57abe8 100644
--- a/lualibs-table.lua
+++ b/lualibs-table.lua
@@ -1094,7 +1094,7 @@ function table.tofile(filename,root,name,specification)
end
end
-local function flattened(t,f,depth)
+local function flattened(t,f,depth) -- also handles { nil, 1, nil, 2 }
if f == nil then
f = { }
depth = 0xFFFF
@@ -1110,19 +1110,16 @@ local function flattened(t,f,depth)
if depth > 0 and type(v) == "table" then
flattened(v,f,depth-1)
else
- f[k] = v
+ f[#f+1] = v
end
end
end
- local n = #f
for k=1,#t do
local v = t[k]
if depth > 0 and type(v) == "table" then
flattened(v,f,depth-1)
- n = #f
else
- n = n + 1
- f[n] = v
+ f[#f+1] = v
end
end
return f