forked from redo/BlockLua
Merge branch 'master'
This commit is contained in:
@@ -13,8 +13,19 @@ function table.map(f, ...)
|
||||
local u = {}
|
||||
for k, _ in pairs(ts[1]) do
|
||||
local args = {}
|
||||
for j = 1, #ts do args[j] = ts[j][i] end
|
||||
u[i] = f(unpack(args))
|
||||
for j = 1, #ts do args[j] = ts[j][k] end
|
||||
u[k] = f(unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
|
||||
function table.mapk(f, ...)
|
||||
local ts = { ... }
|
||||
local u = {}
|
||||
for k, _ in pairs(ts[1]) do
|
||||
local args = {}
|
||||
for j = 1, #ts do args[j] = ts[j][k] end
|
||||
u[k] = f(k, unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
@@ -30,6 +41,17 @@ function table.map_list(f, ...)
|
||||
return u
|
||||
end
|
||||
|
||||
function table.mapi_list(f, ...)
|
||||
local ts = { ... }
|
||||
local u = {}
|
||||
for i = 1, #ts[1] do
|
||||
local args = {}
|
||||
for j = 1, #ts do args[j] = ts[j][i] end
|
||||
u[i] = f(i, unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
|
||||
-- Swap keys/values
|
||||
function table.swap(t)
|
||||
local u = {}
|
||||
@@ -193,7 +215,7 @@ valueToString = function(v, tabLevel, seen)
|
||||
return tostring(v)
|
||||
else
|
||||
--error('table.tostring: table contains a '..t..' value, cannot serialize')
|
||||
return 'nil --[[ cannot serialize ' .. tostring(v) .. ' ]]'
|
||||
return 'nil --[[ ' .. tostring(v) .. ' ]]'
|
||||
end
|
||||
end
|
||||
function table.tostring(t)
|
||||
|
||||
Reference in New Issue
Block a user