[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Absolute stack indexes
- From: Sean Conner <sean@...>
- Date: Thu, 6 Mar 2014 00:39:49 -0500
It was thus said that the Great Rena once stated:
> On Thu, Mar 6, 2014 at 12:24 AM, Coroutines <coroutines@gmail.com> wrote:
>
> > On Wed, Mar 5, 2014 at 9:05 PM, Rena <hyperhacker@gmail.com> wrote:
> > > Am I correct in understanding that this macro:
> > >
> > > #define LUA_ABS_INDEX(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) :
> > \
> > > lua_gettop(L) + (i) + 1)
> > >
> > > will turn a negative stack index into a positive one, which will
> > continue to
> > > refer to the same object even after I push/pop things onto the stack (as
> > > long as I don't remove that object)? If not, how can I achieve this?
> > >
> > > Am I also correct in that this functionality is not exposed in the Lua
> > API,
> > > or has that been changed (or was never true to begin with)?
> > >
> > > --
> > > Sent from my Game Boy.
> >
> >
> > I think you want this one? It's there in 5.2:
> > http://www.lua.org/manual/5.2/manual.html#lua_absindex
> >
> >
> That sounds like what I want. What would I use in 5.1?
I use the following without problems:
static inline int llua_absidx(lua_State *const L,int idx)
{
assert(L != NULL);
assert(idx != 0);
return ((idx < 0) && (idx > LUA_REGISTRYINDEX))
? lua_gettop(L) + idx + 1
: idx;
}
-spc (But I'm compiling with C99)