From e924a7f9ea495df3b2311eb1a0bcb176f34d0545 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 12 May 2010 11:09:20 -0300 Subject: new API function 'lua_absindex' --- lapi.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index a63e4fbd..e32f696d 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.126 2010/05/05 18:53:41 roberto Exp roberto $ +** $Id: lapi.c,v 2.127 2010/05/07 18:10:01 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -61,8 +61,8 @@ static TValue *index2addr (lua_State *L, int idx) { else { Closure *func = clvalue(ci->func); return (idx <= func->c.nupvalues) - ? &func->c.upvalue[idx-1] - : cast(TValue *, luaO_nilobject); + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); } } } @@ -136,6 +136,16 @@ LUA_API const lua_Number *lua_version (lua_State *L) { */ +/* +** convert an acceptable stack index into an absolute index +*/ +LUA_API int lua_absindex (lua_State *L, int idx) { + return (idx > 0 || idx <= LUA_REGISTRYINDEX) + ? idx + : lua_gettop(L) + idx + 1; +} + + LUA_API int lua_gettop (lua_State *L) { return cast_int(L->top - (L->ci->func + 1)); } -- cgit v1.2.3-55-g6feb