--深度拷贝Table function DeepCopy(obj) local InTable = {}; local function Func(obj) if type(obj) ~= "table" then --判断表中是否有表 return obj; end local NewTable = {}; --定义一个新表 InTable[obj] = NewTable; --若表中有表,则先把表给InTable,再用NewTable去接收内嵌的表 for k,v in pair
lua weak table 经常看到lua表中有 weak table的用法, 例如: weak_table = setmetatable({}, {__mode="v"}) 官网上的解释: http://www.lua.org/pil/17.html Weak tables are the mechanism that you use to tell Lua that a reference should not prevent the reclamation of an obje
Lua 内table遍历 在lua中有4种方式遍历一个table,当然,从本质上来说其实都一样,只是形式不同,这四种方式分别是: 1. ipairs for index, value in ipairs(table) do end 注:这种方式的遍历只会从key为1的地方开始,一直以key递增1的顺序来遍历,若找到一个递增不是1的key就结束遍历,无论后面是否仍然是顺序的key. --Sample_1: local tab1 = { [] = , [] = , [] = , [] = , } f
先上代码 function luautil.serialize(t, sort_parent, sort_child) local mark={} local assign={} local function ser_table(tbl,parent) mark[tbl]=parent local tmp={} local sortList = {}; for k,v in pairs(tbl) do sortList[#sortList + 1] = {key=k, value=v}; end