util.table.crush: Optionally use rawset
This commit is contained in:
parent
9f74416ef4
commit
3f0d218f72
|
@ -336,13 +336,22 @@ function util.table.join(...)
|
|||
return ret
|
||||
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 set the table used to override members of `t`
|
||||
-- @tparam[opt=false] boolean raw Use rawset (avoid the metatable)
|
||||
-- @treturn table t (for convenience)
|
||||
function util.table.crush(t, set)
|
||||
for k, v in pairs(set) do
|
||||
t[k] = v
|
||||
function util.table.crush(t, set, raw)
|
||||
if raw then
|
||||
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
|
||||
|
||||
return t
|
||||
|
|
Loading…
Reference in New Issue