Lua - merge tables?

RCIX picture RCIX · Aug 16, 2009 · Viewed 61.5k times · Source

I need to merge two tables, with the contents of the second overwriting contents in the first if a given item is in both. I looked but the standard libraries don't seem to offer this. Where can I get such a function?

Answer

Doug Currie picture Doug Currie · Aug 16, 2009
for k,v in pairs(second_table) do first_table[k] = v end