Lua-如何合并两个表以覆盖两个表中的元素? [英] Lua - How to merge two tables overwriting the elements which are in both?

查看:230
本文介绍了Lua-如何合并两个表以覆盖两个表中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要合并两个表,如果两个表中都有给定项,则第二个表的内容将覆盖第一个表的内容.我看了一下,但标准库似乎没有提供此功能.我在哪里可以得到这样的功能?

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?

推荐答案

for k,v in pairs(second_table) do first_table[k] = v end

这篇关于Lua-如何合并两个表以覆盖两个表中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆