lua-users home
lua-l archive

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


----- Original Message ----- 
From: "Wim Couwenberg" <w.couwenberg@chello.nl>
> Hi,
>
> > #define lua_absindex(L,n) ((n) < 0 ? lua_gettop(L) + (n) + 1 : (n))
>
> better not do it like this, you're bound to say lua_absindex(L, ++x)
sooner
> or later...
> I suggest to make it a function instead.
>
> Bye,
> Wim
>

Wow, just found by chance that this IS in the standard distribution, just
not public ;-)
The implementation shows that I forgot to consider the special index like
the registry, which is negative too.

[lauxlib.c]
/* convert a stack index to positive */
#define abs_index(L, i)  ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
     lua_gettop(L) + (i) + 1)