[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: Julien Cugnière <julien.cugniere@...>
- Date: Mon, 3 May 2010 19:13:44 +0200
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