util.table.crush: Optionally use rawset

This commit is contained in:
Emmanuel Lepage Vallee 2016-05-27 23:24:03 -04:00
parent 9f74416ef4
commit 3f0d218f72
1 changed files with 13 additions and 4 deletions

View File

@ -336,13 +336,22 @@ function util.table.join(...)
return ret return ret
end end
--- Override elements in the first table by the one in the second --- Override elements in the first table by the one in the second.
--
-- Note that this method doesn't copy entries found in `__index`.
-- @tparam table t the table to be overriden -- @tparam table t the table to be overriden
-- @tparam table set the table used to override members of `t` -- @tparam table set the table used to override members of `t`
-- @tparam[opt=false] boolean raw Use rawset (avoid the metatable)
-- @treturn table t (for convenience) -- @treturn table t (for convenience)
function util.table.crush(t, set) function util.table.crush(t, set, raw)
for k, v in pairs(set) do if raw then
t[k] = v for k, v in pairs(set) do
rawset(t, k, v)
end
else
for k, v in pairs(set) do
t[k] = v
end
end end
return t return t