[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: converting a relative stack index into an absolute stack index: a little someting missing in the C API?
- From: Brian Maher <brimworks@...>
- Date: Fri, 14 May 2010 06:14:54 -0700
I've got a copy of lauxlib.c's abs_index() macro copied into almost
all of my C extensions. I agree that it would be nice if this macro
was part of the public API for Lua.
On Mon, May 3, 2010 at 10:13 AM, Julien Cugnière
<julien.cugniere@gmail.com> wrote:
> 2010/5/3 Benoit Germain <bgermain@ubisoft.fr>:
>>
>> 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)?
>
> lauxlib.c uses the following private macro :
>
> /* convert a stack index to positive */
> #define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
> lua_gettop(L) + (i) + 1)
>
> It does the same as your function, so your function is correct :-) I
> also wrote a function just like yours, so yes, I think it would make a
> useful addition to the API.
>
> There are basically two types of Lua bindings developers in the world
> : those that use some kind of abs_index() function, and those that
> have never been bitten by negative indices :-)
>
> --
> Julien Cugnière
>
--
Brian Maher >> Glory to God <<