Lua是什么意思?

前端之家收集整理的这篇文章主要介绍了Lua是什么意思?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经看到角色’#’被添加到变量的前面很多在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

道歉如果这已经被问到,我已经在互联网上搜索了很多,但我似乎没有找到答案.提前致谢!

解决方法

那就是 length operator

The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is,the usual meaning of string length when each character is one byte).

The length of a table t is defined to be any integer index n such that t[n] is not nil and t[n+1] is nil; moreover,if t[1] is nil,n can be zero. For a regular array,with non-nil values from 1 to a given n,its length is exactly that n,the index of its last value. If the array has “holes” (that is,nil values between other non-nil values),then #t can be any of the indices that directly precedes a nil value (that is,it may consider any such nil value as the end of the array).

猜你在找的Lua相关文章