new API function 'lua_absindex'
This commit is contained in:
16
lapi.c
16
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user