lunarmodules/lua-compat-5.3

table.maxn

EPuncker opened this issue · 2 comments

table.maxn was deprecated at 5.2, does it have any alternative?

Some people says this is fine:

table.maxn = function(t) return #t end

But others disagree, so I'm lost.

table.maxn = function(t) return #t end

But others disagree, so I'm lost.

table.maxn is literally:

function maxn(t)
    local max = 0
    for k in pairs(t) do
        if type(k) == "number" and k > max then
            max = k
        end
    end
    return max
end

If you find yourself needing table.maxn you've probably done something wrong.

Note that lua-compat-5.3 is to make lua 5.1/5.2 act like lua 5.3; not the other way around.

            

thank you