lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> -- @func table.merge: Merge two tables
> -- If there are duplicate fields, u's will be used. The metatable of
> -- the returned table is that of t
> --   @param t, u: tables
> -- returns
> --   @param r: the merged table
> function table.merge (t, u)
>   local r = table.clone (t)
>   for i, v in pairs (u) do
>     r[i] = v
>   end
>   return r
> end
>
> For the purpose of merging argument lists it appears that this table.merge
> doesn't work quite as intended.

Oops. This is what I get for happily writing code without testing it.
Where I called "table.merge" I should have called "list.concat":

-- @func list.concat: Concatenate two lists
--   @param l: list
--   @param m: list
-- returns
--   @param n: result {l[1] ... l[table.getn (l)], m[1] ...
--     m[table.getn (m)]}
function list.concat (l, m)
  local n = {}
  for _, v in ipairs (l) do
    table.insert (n, v)
  end
  for _, v in ipairs (m) do
    table.insert (n, v)
  end
  return n
end

-- 
http://www.mupsych.org/~rrt/
penitent, a.  undergoing or awaiting punishment (Bierce)