嵌套数组的长度 Lua

我不知道如何获得一个嵌套了3个深度矩阵的矩阵的长度。所以简单地说,代码的功能是......查看出版商是否已经存在于数组中,然后它要么在数组中添加一个新的列,包括新的出版商和相应的系统,要么将新系统添加到现有的数组出版商中。

output[k][1] 是出版商数组

output[k][2][l] 是系统

其中第一个 [] 是不同出版商的数量,第二个 [] 是同一个出版商中不同系统的数量。

那么我该如何找出第三个深度数组的长度呢?

function reviewPubCount()
    local output = {}
    local k = 0
    for i = 1, #keys do
        if string.find(tostring(keys[i]), '_') then
            key = Split(tostring(keys[i]), '_')
            for j = 1, #reviewer_code do
                if key[1] == reviewer_code[j] and key[1] ~= '' then
                    k = k + 1
                    output[k] = {}
                   -- output[k] = reviewer_code[j]
                    for l = 1, k do
                        if output[l][1] == reviewer_code[j] then
                            ltable = output[l][2]
                            temp = table.getn(ltable)
                            output[l][2][temp+1] = key[2]
                        else
                            output[k][1] = reviewer_code[j]
                            output[k][2][1] = key[2]
                        end
                    end
                end
            end
        end
    end
    return output
end

代码已经修复,在此供参考:http://codepad.org/3di3BOD2#output

点赞
用户1442917
用户1442917

你应该可以用 #t 替换 table.getn(t) (在 Lua 5.1 中已被弃用,在 Lua 5.2 中被删除);而不是这样:

ltable = output[l][2]
temp = table.getn(ltable)
output[l][2][temp+1] = key[2]

尝试下面的代码:

output[l][2][#output[l][2]+1] = key[2]

或者这样:

table.insert(output[l][2], key[2])
2013-10-12 02:49:42