[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API question - modifing table
- From: Jamie Webb <j@...>
- Date: Wed, 11 Aug 2004 12:47:38 +0100
On Wed, Aug 11, 2004 at 03:34:45PM +0400, Dmitry Samersoff wrote:
> lua_tostring remove value from stack. Isn't it ?
No, it doesn't. There's your problem.
> lua_pushstring(L, "RRN");
> lua_pushstring(L, "abcd");
> lua_settable(L,-3);
Because each iteration of the loop was adding an extra key-value pair
to the stach, the table is no longer at index -3, it's at index
-(num_keys*2+1).
Probably what you wanted was to do lua_pop(1) to remove the value
rather than re-pushing the key.
-- Jamie Webb