听起来像是一个“让我为你搜索一下”的问题,但不知何故我找不到答案。table.getn
和Lua #
运算符一样,只计算具有整数键的条目
tbl = {}
tbl["test"] = 47
tbl[1] = 48
print(#tbl, table.getn(tbl)) -- prints "1 1"
count = 0
for _ in pairs(tbl) do count = count + 1 end
print(count) -- prints "2"
如何在不计算的情况下获得所有条目的数量?
https://stackoverflow.com/questions/2705793
复制相似问题