I am using a queue in 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
I access the queue using the following commands:
list = List.New
List.PushRight(list, position)
local popped = List.PopLeft(list)
List.PushRight(list, popped)
It crashes in the PushRight command on:
local last = list.last + 1
The error is:
attempt to index local 'list' (a function value)
'list' is clearly not a function value. It is a List that I instantiated with the key 'last' which I should be able to access with the value -1. Why is it calling list a function?
Thanks.