[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: absolute stack index
- From: Tobias Käs <tobias.kaes@...>
- Date: Sun, 29 Jun 2003 20:01:45 +0200
----- 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)