表插入给出零错误

时间:2013-05-07 03:52:51

标签: lua lua-table

我的lua代码中有以下功能。我收到错误Attempt to call field 'insert' (a nil value)

我在主要的chunck

上面
local cardDeck;
local suits = {"h","d","c","s"};

然后在功能

function createDeck()
    cardDeck = {};
    for i=1, 4 do
        for j=1, 13 do
            local tempCard = suits[i]..j;--PRINT SHOW VALID VALUE HERE i.e. "h1","d2" etc
                table.insert(cardDeck,tempCard); --THIS LINE IS ERROR
        end
    end
end

1 个答案:

答案 0 :(得分:4)

您确定自己没有在程序的其他地方定义table吗?

> table.insert({},1)
> table = {}
> table.insert({},1)
stdin:1: attempt to call field 'insert' (a nil value)
stack traceback:
    stdin:1: in main chunk
    [C]: ?