lua-users home
lua-l archive

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


The Reference Manual indicates that the following functions raise
non-memory errors:

  lua_next [-1, +(2|0), e]
  lua_gc [-0, +0, e]
  luaL_getmetafield [-0, +(0|1), e]

As far as I see, lua_next only raises an error if the key is invalid.
Am I right that that traversing a table by starting with nil and not
making any modification to the table (like in the example given in the
description of lua_next) ensures the key is valid so that the function
does not raise an error?

lua_gc is a more complicated function, but initially I don't see it
raising an error.  Would that be if __gc raised? (which by convention
it should not).

luaL_getmetafield is defined in terms of six API functions.  The only
one that raises an error is lua_pushstring, and it is a memory error
(type m).

Are these intentional?  I understand that the implementation can be
stricter than the specification, so the doc is not necessarily
incorrect, but lua_next and luaL_getmetafield do not call metamethods,
so it seems unusual for them to raise errors.

The reason I ask concerns the use of lua_next while ensuring exception
safety (zero side effects).