mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 09:03:01 +00:00
wea.table_map(): Add api function
This commit is contained in:
parent
1e677c1f3f
commit
8eb9a8ed0f
1 changed files with 14 additions and 0 deletions
|
@ -65,3 +65,17 @@ function worldeditadditions.table_tostring(tbl, sep, new_line)
|
||||||
end
|
end
|
||||||
return ret:concat("")
|
return ret:concat("")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Executes the given function on every item in the given table.
|
||||||
|
-- Ignores return values that are nil and doesn't insert them into the table.
|
||||||
|
-- @param tbl table The table to operate on.
|
||||||
|
-- @param func function The function to execute on every item in the table.
|
||||||
|
-- @returns table A new table containing the return values of the function.
|
||||||
|
function worldeditadditions.table_map(tbl, func)
|
||||||
|
local result = {}
|
||||||
|
for i,value in ipairs(tbl) do
|
||||||
|
local newval = func(value, i)
|
||||||
|
if newval ~= nil then table.insert(tbl, newval) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue