lua-users home
lua-l archive

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


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