[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible 4.0Beta Bug??
- From: Edgar Toernig <froese@...>
- Date: Sun, 24 Sep 2000 23:38:25 +0200
Hi,
> // expect a table as only argument on the stack.
> lua_pushnil(ls); /* first key */
> while (lua_next(ls, 1) != 0) {
> /* `key' is at index -2 and `value' at index -1 */
> printf("%s - %s - %s - %s\n",
> lua_tostring(ls, -2), lua_type(ls, -2),
> lua_tostring(ls, -1), lua_type(ls, -1));
> lua_pop(ls, 1); /* removes `value'; keeps `index' for next
> iteration */
> }
[snipp]
>
> Here's the Lua code:
>
> t1 = {a=1, b=2, c=3, d=4, e=5}
> t2 = {'a', 'b', 'c', 'd', 'e', 'f'}
>
> LuaCallMe(t1) -- OK
> LuaCallMe(t2) -- Error
>
> Here's the output:
> a - string - 1 - number
> c - string - 3 - number
> b - string - 2 - number
> e - string - 5 - number
> d - string - 4 - number
> 1 - number - a - string
> error: invalid key for 'next
lua_tostring & co convert the data in place. So, first
your printf-statement depends on the C-compiler (what is
evaluated first, lua_tostring or the corresponding lua_type?)
and second, the following lua_next will fail because it
can't find the old key - it's now a string.
Ciao, ET.