Lua table 赋值奇怪的问题

各位大神 帮忙看看这段代码有啥问题,r在某些情况会是空,就算走过了
if (r == nil) then r = {} end ,r也可能是空的 最终就在table.insert那边报错 说table expected 而且不是必现的 有大神知道为什么吗?

—获得某个战报id的
function BattleGuideList:GetListByReportId(id)
local r = {}
for i,v in ipairs(self.list) do
local report_id = tonumber(v.a)
if report_id == id then
local key = tostring(v.c)
if r == nil then r = {} end – 有设置
table.insert(r , v) – 还是空的?
end
end
return r
end

查一下你的key是不是nil

嗯 你说的也有可能~