lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12 February 2014 00:28, Kevin Martin <kev82@khn.org.uk> wrote:
> Hi,
>
> The documentation for lua_next refers me to next, which says
>
> "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."
>
> Does this mean I can do
>
> //Assume there is a table at index 1
> lua_pushnil(l);
> while(lua_next(l, 1) != 0) {
>         lua_pop(l, 1);
>
>         lua_pushvalue(l, -1);
>         lua_pushnil(l);
>         lua_settable(l, 1);
> }
>
> Thanks,
> Kevin
>
>

Yes, that will work. It's the exact implementation of the `wipe`
function in lua-wow (a Lua distribution that includes a few tweaks to
make it more like World of Warcraft's embedded Lua environment):

https://github.com/cogwheel/lua-wow/blob/master/src/lwowlib.c#L266-L279