[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Clearing tables
- From: Wim Couwenberg <w.couwenberg@...>
- Date: Sun, 18 May 2003 13:09:19 +0200
> However this 'non-defined index' problem begins to worry me. What kind of
> index is this, and how do you prevent it? Moreover, would it be possible to
> port Adam D. Moss' version to C?
Don't worry about the non-defined index problem (if it can
be called a problem at all.) It is rather subtle and
probably of no consequence under normal circumstances. The
ADM version can be rewritten as follows:
/* suppose that the table is at stack index "table" */
void zap_table(lua_State *L, int table)
{
lua_pushnil(L);
while (lua_next(L, table))
{
lua_pop(L, 1); /* pop value */
lua_pushvalue(L, -1); /* duplicate the key */
lua_pushnil(L);
lua_settable(L, table); /* zap the key */
}
}
Bye,
Wim