[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: invalid key to 'next'
- From: Agi Shi <nullsquared@...>
- Date: Sun, 24 May 2009 08:04:41 -0400
I see. However, the only iteration I'm doing in Lua is this:
local function buttons(table)
local pos = vec2(0, 0)
for key, val in pairs(table) do
for key2, val2 in pairs(val) do
--log(type(val2))
val2.position = vec2(pos.x, pos.y)
pos.x = pos.x + val2.size.x
end
end
return table
end
I'm not modifying the table itself, only the values of the table. And
I've now realized that naming the table 'table' is a bad idea, so I've
changed it (but the same issue occurs).
On Sun, May 24, 2009 at 6:08 AM, Jim Whitehead II <jnwhiteh@gmail.com> wrote:
>
> On Sun, May 24, 2009 at 3:06 AM, Agi Shi <nullsquared@gmail.com> wrote:
> > Hi all! I'm nullsquared, new to the mailing list, with a bit of a
> > complicated situation.
> > This code: http://lua.pastebin.com/f7b33bcca
> > Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
> > fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
> > When sheet.update() is called, it iterates over the passed in table and
> > creates a GUI; the table itself is only read, not modified, and it is
> > iterated over via standard luabind table iterators.
> > I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
>
> As stated in the Lua reference manual, this means that during the
> iteration you are assigning to a key that didn't exist prior to the
> iteration. This was the case in Lua 5.0, however the error is not
> guaranteed to happen each and every time.
>
> Keep in mind that the assignment can be setting the element to nil.
> You can do any assignments to keys that already existed prior to the
> iteration, just not any new ones.
>
> - Jim