Add helper functions to update/merge tables.

This commit is contained in:
iliekprogrammar 2021-11-10 02:50:49 +08:00
parent a7bc460fae
commit fa22ec4dd0
No known key found for this signature in database
GPG Key ID: 8E7B20514DBCFBFA
1 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,27 @@
mcl_util = {}
-- Updates all values in t using values from to*.
function table.update(t, ...)
for _, to in ipairs{...} do
for k,v in pairs(to) do
t[k] = v
end
end
return t
end
-- Updates nil values in t using values from to*.
function table.update_nil(t, ...)
for _, to in ipairs{...} do
for k,v in pairs(to) do
if t[k] == nil then
t[k] = v
end
end
end
return t
end
-- Based on minetest.rotate_and_place
--[[