fmsl/std/table.lua

25 lines
543 B
Lua

-- Remove a key from a table and return the value
-- @param table: Table
-- @param key: Any
-- @return Any
function table.remove_key(table, key)
local value = table[key]
table[key] = nil
return value
end
-- Merge multiple tables into a new table, with later tables taking precedence
-- @param ...: Table
-- @return Table
function table.merge_new(...)
local result = {}
for _, table in ipairs({...}) do
if table then
for key, value in pairs(table) do
result[key] = value
end
end
end
return result
end