summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-12 11:09:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-12 11:09:20 -0300
commite924a7f9ea495df3b2311eb1a0bcb176f34d0545 (patch)
tree8764c3c54c234c5a0ac2a79c9828b5d221020f99 /lapi.c
parent4fd76b8148eae1a1be43a265588bd0fc3959c33b (diff)
downloadlua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.tar.gz
lua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.tar.bz2
lua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.zip
new API function 'lua_absindex'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/lapi.c b/lapi.c
index a63e4fbd..e32f696d 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.126 2010/05/05 18:53:41 roberto Exp roberto $ 2** $Id: lapi.c,v 2.127 2010/05/07 18:10:01 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -61,8 +61,8 @@ static TValue *index2addr (lua_State *L, int idx) {
61 else { 61 else {
62 Closure *func = clvalue(ci->func); 62 Closure *func = clvalue(ci->func);
63 return (idx <= func->c.nupvalues) 63 return (idx <= func->c.nupvalues)
64 ? &func->c.upvalue[idx-1] 64 ? &func->c.upvalue[idx-1]
65 : cast(TValue *, luaO_nilobject); 65 : cast(TValue *, luaO_nilobject);
66 } 66 }
67 } 67 }
68} 68}
@@ -136,6 +136,16 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
136*/ 136*/
137 137
138 138
139/*
140** convert an acceptable stack index into an absolute index
141*/
142LUA_API int lua_absindex (lua_State *L, int idx) {
143 return (idx > 0 || idx <= LUA_REGISTRYINDEX)
144 ? idx
145 : lua_gettop(L) + idx + 1;
146}
147
148
139LUA_API int lua_gettop (lua_State *L) { 149LUA_API int lua_gettop (lua_State *L) {
140 return cast_int(L->top - (L->ci->func + 1)); 150 return cast_int(L->top - (L->ci->func + 1));
141} 151}