0

I've copied a List "class" and am modifying it so the "new" function can take a variable amount of parameters and it'll add those values to the list itself. However, the 'arg' variable is always nil and I'm not sure why.

List = {}

function List.new(...)
    local obj = { first = 0, last = -1 }

    if arg ~= nil then
        -- push any values passed in
        for k,v in pairs(arg) do
            List.pushleft(obj, v)
        end
    end

    return obj
end

function List.pushleft(list, value)
    local first = list.first - 1
    list.first = first
    list[first] = value
end

local test = List.new("Food", "Bandage")
user441521
  • 6,942
  • 23
  • 88
  • 160
  • So if I add: local arguments = {...} then I can loop over arguments and it works. I thought that's basically what the arg variable is supposed to be created for us behind the scenes? That's what the Lua doc's I'm seeing say. – user441521 Dec 02 '15 at 04:33
  • 4
    I think the default to `arg` was removed in Lua 5.2 – hjpotter92 Dec 02 '15 at 04:57
  • See http://stackoverflow.com/a/22308500/107090. – lhf Dec 02 '15 at 12:00

0 Answers0