tableA = {}
tableB = {}
setmetatable(tableA ,tableB )
tableB .__mode = "k" -- tableB .__mode = "v" 或者tableB .__mode = "kv"
这样,tableA将是一个weak table
当tableA中的键的引用为0,或者对应键的值的引用为0是,就会删除正行属性:
testfunction()
local key = {}
tableA[key] = 1
local key = {}
tableA[key] = 2
end
collectgarbage();
for k,v in pairs(tableA) do
print(v) -- 2
end
原文地址:http://www.cnblogs.com/aj007/p/3998689.html