diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-12 11:09:20 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-12 11:09:20 -0300 |
commit | e924a7f9ea495df3b2311eb1a0bcb176f34d0545 (patch) | |
tree | 8764c3c54c234c5a0ac2a79c9828b5d221020f99 /lauxlib.c | |
parent | 4fd76b8148eae1a1be43a265588bd0fc3959c33b (diff) | |
download | lua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.tar.gz lua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.tar.bz2 lua-e924a7f9ea495df3b2311eb1a0bcb176f34d0545.zip |
new API function 'lua_absindex'
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.208 2010/04/14 15:14:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.209 2010/05/10 15:25:02 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,11 +24,6 @@ | |||
24 | #include "lauxlib.h" | 24 | #include "lauxlib.h" |
25 | 25 | ||
26 | 26 | ||
27 | /* convert a stack index to positive */ | ||
28 | #define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ | ||
29 | lua_gettop(L) + (i) + 1) | ||
30 | |||
31 | |||
32 | /* | 27 | /* |
33 | ** {====================================================== | 28 | ** {====================================================== |
34 | ** Traceback | 29 | ** Traceback |
@@ -442,7 +437,7 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { | |||
442 | 437 | ||
443 | LUALIB_API int luaL_ref (lua_State *L, int t) { | 438 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
444 | int ref; | 439 | int ref; |
445 | t = abs_index(L, t); | 440 | t = lua_absindex(L, t); |
446 | if (lua_isnil(L, -1)) { | 441 | if (lua_isnil(L, -1)) { |
447 | lua_pop(L, 1); /* remove from stack */ | 442 | lua_pop(L, 1); /* remove from stack */ |
448 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ | 443 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
@@ -463,7 +458,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
463 | 458 | ||
464 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { | 459 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
465 | if (ref >= 0) { | 460 | if (ref >= 0) { |
466 | t = abs_index(L, t); | 461 | t = lua_absindex(L, t); |
467 | lua_getfield(L, t, freelist); | 462 | lua_getfield(L, t, freelist); |
468 | lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ | 463 | lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ |
469 | lua_pushinteger(L, ref); | 464 | lua_pushinteger(L, ref); |
@@ -600,7 +595,7 @@ LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { | |||
600 | 595 | ||
601 | 596 | ||
602 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { | 597 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { |
603 | obj = abs_index(L, obj); | 598 | obj = lua_absindex(L, obj); |
604 | if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ | 599 | if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ |
605 | return 0; | 600 | return 0; |
606 | lua_pushvalue(L, obj); | 601 | lua_pushvalue(L, obj); |