lua-users home
lua-l archive

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


Falko Poiker <fpoiker@relic.com> wrote:
> Is there a way to find out if an index is valid in a table?  I tested the
> above, and lua_getnumber returns 0.0 if there isn't anything at that 
index.
> Is there something like lua_isindex() ?

rawgettable can do the same thing:

In lua:

function isindex(table)
  if rawgettable(table, 1) == nil then
    return 0
  end
  return 1
end

In C:

int lua_isindex(lua_Object table)
{
  if ( lua_isnil(lua_rawgettable(table, "1")) == 1 )
  {
    return 0
  }
  return 1
}
 
Steve