diff --git a/lapi.c b/lapi.c index 6f8037c5..44001697 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ +** $Id: lapi.c,v 1.174 2002/02/14 21:46:13 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -30,7 +30,7 @@ const char lua_ident[] = #ifndef api_check -#define api_check(L, o) /* nothing */ +#define api_check(L, o) ((void)1) #endif #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->ci->base)) @@ -57,14 +57,10 @@ static TObject *negindex (lua_State *L, int index) { } -TObject *luaA_index (lua_State *L, int index) { - if (index > 0) { - api_check(L, index <= L->top - L->ci->base); - return L->ci->base+index-1; - } - else - return negindex(L, index); -} +#define luaA_index(L, index) \ + ( (index > 0) ? \ + (api_check(L, index <= L->top - L->ci->base), L->ci->base+index-1) : \ + negindex(L, index)) static TObject *luaA_indexAcceptable (lua_State *L, int index) { diff --git a/lapi.h b/lapi.h index 7a475ac9..61f18b88 100644 --- a/lapi.h +++ b/lapi.h @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 1.19 2000/08/28 17:57:04 roberto Exp roberto $ +** $Id: lapi.h,v 1.20 2000/08/31 14:08:27 roberto Exp roberto $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ @@ -11,7 +11,6 @@ #include "lobject.h" -TObject *luaA_index (lua_State *L, int index); void luaA_pushobject (lua_State *L, const TObject *o); #endif diff --git a/ltests.c b/ltests.c index 5130354b..50836dfc 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 1.109 2002/02/14 21:42:22 roberto Exp roberto $ +** $Id: ltests.c,v 1.110 2002/03/04 15:26:56 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -41,6 +41,8 @@ static lua_State *lua_state = NULL; int islocked = 0; +#define index(L,k) (L->ci->base+(k) - 1) + static void setnameval (lua_State *L, const char *name, int val) { lua_pushstring(L, name); @@ -165,7 +167,7 @@ static int listcode (lua_State *L) { Proto *p; luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); - p = clvalue(luaA_index(L, 1))->l.p; + p = clvalue(index(L, 1))->l.p; lua_newtable(L); setnameval(L, "maxstack", p->maxstacksize); setnameval(L, "numparams", p->numparams); @@ -184,7 +186,7 @@ static int listk (lua_State *L) { int i; luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); - p = clvalue(luaA_index(L, 1))->l.p; + p = clvalue(index(L, 1))->l.p; lua_newtable(L); for (i=0; isizek; i++) { lua_pushnumber(L, i+1); @@ -202,7 +204,7 @@ static int listlocals (lua_State *L) { const char *name; luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, "Lua function expected"); - p = clvalue(luaA_index(L, 1))->l.p; + p = clvalue(index(L, 1))->l.p; while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) lua_pushstring(L, name); return i-1; @@ -242,13 +244,13 @@ static int mem_query (lua_State *L) { static int hash_query (lua_State *L) { if (lua_isnone(L, 2)) { luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); - lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); + lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); } else { - TObject *o = luaA_index(L, 1); + TObject *o = index(L, 1); Table *t; luaL_check_type(L, 2, LUA_TTABLE); - t = hvalue(luaA_index(L, 2)); + t = hvalue(index(L, 2)); lua_pushnumber(L, luaH_mainposition(t, o) - t->node); } return 1; @@ -270,7 +272,7 @@ static int table_query (lua_State *L) { const Table *t; int i = luaL_opt_int(L, 2, -1); luaL_check_type(L, 1, LUA_TTABLE); - t = hvalue(luaA_index(L, 1)); + t = hvalue(index(L, 1)); if (i == -1) { lua_pushnumber(L, t->sizearray); lua_pushnumber(L, sizenode(t));