lua中有没有一种可变的复制表格的方法,不会影响原始表格?

我正在尝试制作一个排序函数,我需要从表格/数组中删除重复项,以便获取前三个,但当我这样做时,它会更改原始表格/数组。

function removeDuplicates(list)

    input = list
    i = 0
    while i < #input
    do
        if input[i] == input[i + 1] then
            table.remove(input, i)
        else
            i = i + 1
        end
    end

    return input
end

有没有一些聪明,适当的方法来做到这一点?我能够遍历数组并将每个值设置为新数组吗?

原文链接 https://stackoverflow.com/questions/70484343

点赞