lua-users home
lua-l archive

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

It was thus said that the Great oliver once stated:
> Programmers make mistakes when using library functions/methods, utility or
> not. For optimal productivity, a library should assert its preconditions, at
> least in debug build. It is an error *not* to check. Since some of us have
> to (for variety of reasons) use pre-built release-mode Lua DLL, where
> preconditions are therefore not asserted, and given that the
> "is-acceptable-index" formula is not trivial, and that this precondition is
> so prevalent in Lua lib, there should at least be a Lua lib function that
> allows to validate stack indices.

  I think you gave the solution in another email---lua_gettop()!  Here:

int mylua_isacceptable(lua_State *L,int idx)
  return abs(idx) <= lua_gettop(L);

  -spc (Or am I missing something?)