在 Lua 中使用队列时出错。

我在 Lua 中使用了一个队列

http://www.lua.org/pil/11.4.html

List = {}
function List.New ()
    return {first = 0, last = -1}
end

function List.PushRight (list, value)
    local last = list.last + 1
    list.last = last
    list[last] = value
end

function List.PopLeft (list)
    local first = list.first
    if first > list.last then print("error: list is empty") end
    local value = list[first]
    list[first] = nil        -- to allow garbage collection
    list.first = first + 1
    return value
end

我使用以下命令访问队列:

list = List.New

List.PushRight(list, position)

local popped = List.PopLeft(list)

List.PushRight(list, popped)

它在PushRight命令中崩溃:

local last = list.last + 1

错误是:

attempt to index local 'list' (a function value)

'list' 明显不是函数值。它是一个我实例化的带有键'last'的List,我应该能够使用值-1来访问它。为什么它正在调用list作为函数?

谢谢。

点赞