When I code a binding, I find myself having helper functions manipulating items on the stack whose index is provided by the caller. Often enough, this index is relative to the stack top.
It happens that I found a bug where the called function used this top-relative index after having itself pushed an item on the stack, thus causing the reference to something unexpected.
I therefore found myself in the need, for the called function, to ensure that the provided stack index is valid whenever it is used. So I coded this awesome piece of software:
__inline int lua_absindex( lua_State * const L, int const _idx)
// positive or pseudo-index: return the index, else convert to absolute stack index
return (_idx > 0) ? _idx : (_idx <= LUA_REGISTRYINDEX) ? _idx : (lua_gettop( L) + 1 + _idx);
Now, maybe the equivalent already exists in the current API (5.1.4), but I missed it. And in the event it is not the case, maybe this could be considered a useful addition to 5.2 (provided it properly covers all cases, of course)?