当前位置:网站首页>lua-复制一份table,修改新的table,不改变原来的table
lua-复制一份table,修改新的table,不改变原来的table
2022-08-11 05:31:00 【星际行走】
local table1 = {
{1,2,3}, {4,5,6}}
local table2 = UITools.CopyTable(table1)
table2[1][1] = 2
print("table1 =", PrintTable(table1))
print("table2 =", PrintTable(table2))
-- 复制一份table,修改不会影响原来的表
function UITools.CopyTable(table1)
local newTable = {}
for key, value in pairs(table1) do
if type(value) == "table" then
newTable[key] = UITools.CopyTable(value)
else
newTable[key] = value
end
end
return newTable
end
边栏推荐
猜你喜欢
随机推荐
Unity两种VR环境配置方法
USB in NRZI to encode the data
微信小程序启动页的实现
Day 69
Byte (byte) and bit (bit)
C# async/await异步操作实例
Pinyougou project combat notes
【LeetCode-56】合并区间
微信小程序云开发项目wx-store代码详解
Day 82
USB URB
Lua 快速入门(二)——函数(Function)
Real-time Feature Computing Platform Architecture Methodology and Practice Based on OpenMLDB
自己动手写RISC-V的C编译器-00环境配置
【LeetCode-13】罗马数字转整数
星盟-pwn-fog
IndexError: index 9 is out of bounds for axis 0 with size 9;数组下标溢出问题
Day 76
buuctf hacknote
Lua 快速入门(五)——协程(thread)