我在Lua中经常看到变量前面加上井号 '#'。
它是什么作用?
例子:
-- sort AIs in currentlevel
table.sort(level.ais, function(a,b) return a.y < b.y end)
local curAIIndex = 1
local maxAIIndex = #level.ais
for i = 1,#currentLevel+maxAIIndex do
if level.ais[curAIIndex].y+sprites.monster:getHeight() < currentLevel[i].lowerY then
table.insert(currentLevel, i, level.ais[curAIIndex])
curAIIndex = curAIIndex + 1
if curAIIndex > maxAIIndex then
break
end
end
end
如果已经有人问过这个问题,我很抱歉,我在互联网上搜索了很多但好像没有找到答案。提前感谢!
unexpected symbol near '#'
呢?这是别人的代码,似乎没有其他人遇到问题... - Michael