lua-users home
lua-l archive

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


In Lua a good way to check if a table t is empty is to check if next(t) == nil.

What is the best way to check if a table is empty using the C API? Is it basically the same technique?

    // table is on stack at index t
    lua_pushnil(L); // nil key
    if (lua_next(L, t))
    {
        // not empty
        lua_pop(L, 2);
    }
    else
    {
       // empty
    }

Or is there a better way?