[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Invalid key for "next" - Setting value nil while traversing
- From: Mitchell Hashimoto <mitchell.hashimoto@...>
- Date: Tue, 3 Mar 2009 09:53:41 -0800
This is exactly the part in the manual I read and assumed it was for
just the scripting language, and not the C API, which I am using. But
since making the change to pushnil to pushinteger 0, it has fixed the
problem.
I'm still unsure why.
Mitchell
On Tue, Mar 3, 2009 at 5:57 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Now, I ask, should I not ever be setting a value to nil mid-traversal?
>> Why does this cause problems as I'm not modifying the key at all? My
>> initial assumptions were that some sort of GC was occuring before the
>> next iteration, which confused lua_next, since the value was GC'd
>> (nil). Is this correct?
>
> This should cause no problems. It is explicitly allowed:
>
> * http://www.lua.org/manual/5.1/manual.html#pdf-next
> The behavior of next is undefined if, during the traversal, you assign
> any value to a non-existent field in the table. You may however modify
> existing fields. In particular, you may clear existing fields.
>
> -- Roberto
>