diff options
-rw-r--r-- | lapi.c | 16 | ||||
-rw-r--r-- | lapi.h | 3 | ||||
-rw-r--r-- | ltests.c | 18 |
3 files changed, 17 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lapi.c,v 1.174 2002/02/14 21:46:13 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 | */ |
@@ -30,7 +30,7 @@ const char lua_ident[] = | |||
30 | 30 | ||
31 | 31 | ||
32 | #ifndef api_check | 32 | #ifndef api_check |
33 | #define api_check(L, o) /* nothing */ | 33 | #define api_check(L, o) ((void)1) |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->ci->base)) | 36 | #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) { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
60 | TObject *luaA_index (lua_State *L, int index) { | 60 | #define luaA_index(L, index) \ |
61 | if (index > 0) { | 61 | ( (index > 0) ? \ |
62 | api_check(L, index <= L->top - L->ci->base); | 62 | (api_check(L, index <= L->top - L->ci->base), L->ci->base+index-1) : \ |
63 | return L->ci->base+index-1; | 63 | negindex(L, index)) |
64 | } | ||
65 | else | ||
66 | return negindex(L, index); | ||
67 | } | ||
68 | 64 | ||
69 | 65 | ||
70 | static TObject *luaA_indexAcceptable (lua_State *L, int index) { | 66 | static TObject *luaA_indexAcceptable (lua_State *L, int index) { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.h,v 1.19 2000/08/28 17:57:04 roberto Exp roberto $ | 2 | ** $Id: lapi.h,v 1.20 2000/08/31 14:08:27 roberto Exp roberto $ |
3 | ** Auxiliary functions from Lua API | 3 | ** Auxiliary functions from Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,7 +11,6 @@ | |||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | 12 | ||
13 | 13 | ||
14 | TObject *luaA_index (lua_State *L, int index); | ||
15 | void luaA_pushobject (lua_State *L, const TObject *o); | 14 | void luaA_pushobject (lua_State *L, const TObject *o); |
16 | 15 | ||
17 | #endif | 16 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.109 2002/02/14 21:42:22 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.110 2002/03/04 15:26:56 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,6 +41,8 @@ static lua_State *lua_state = NULL; | |||
41 | int islocked = 0; | 41 | int islocked = 0; |
42 | 42 | ||
43 | 43 | ||
44 | #define index(L,k) (L->ci->base+(k) - 1) | ||
45 | |||
44 | 46 | ||
45 | static void setnameval (lua_State *L, const char *name, int val) { | 47 | static void setnameval (lua_State *L, const char *name, int val) { |
46 | lua_pushstring(L, name); | 48 | lua_pushstring(L, name); |
@@ -165,7 +167,7 @@ static int listcode (lua_State *L) { | |||
165 | Proto *p; | 167 | Proto *p; |
166 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 168 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
167 | 1, "Lua function expected"); | 169 | 1, "Lua function expected"); |
168 | p = clvalue(luaA_index(L, 1))->l.p; | 170 | p = clvalue(index(L, 1))->l.p; |
169 | lua_newtable(L); | 171 | lua_newtable(L); |
170 | setnameval(L, "maxstack", p->maxstacksize); | 172 | setnameval(L, "maxstack", p->maxstacksize); |
171 | setnameval(L, "numparams", p->numparams); | 173 | setnameval(L, "numparams", p->numparams); |
@@ -184,7 +186,7 @@ static int listk (lua_State *L) { | |||
184 | int i; | 186 | int i; |
185 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 187 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
186 | 1, "Lua function expected"); | 188 | 1, "Lua function expected"); |
187 | p = clvalue(luaA_index(L, 1))->l.p; | 189 | p = clvalue(index(L, 1))->l.p; |
188 | lua_newtable(L); | 190 | lua_newtable(L); |
189 | for (i=0; i<p->sizek; i++) { | 191 | for (i=0; i<p->sizek; i++) { |
190 | lua_pushnumber(L, i+1); | 192 | lua_pushnumber(L, i+1); |
@@ -202,7 +204,7 @@ static int listlocals (lua_State *L) { | |||
202 | const char *name; | 204 | const char *name; |
203 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 205 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
204 | 1, "Lua function expected"); | 206 | 1, "Lua function expected"); |
205 | p = clvalue(luaA_index(L, 1))->l.p; | 207 | p = clvalue(index(L, 1))->l.p; |
206 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 208 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
207 | lua_pushstring(L, name); | 209 | lua_pushstring(L, name); |
208 | return i-1; | 210 | return i-1; |
@@ -242,13 +244,13 @@ static int mem_query (lua_State *L) { | |||
242 | static int hash_query (lua_State *L) { | 244 | static int hash_query (lua_State *L) { |
243 | if (lua_isnone(L, 2)) { | 245 | if (lua_isnone(L, 2)) { |
244 | luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); | 246 | luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
245 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); | 247 | lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); |
246 | } | 248 | } |
247 | else { | 249 | else { |
248 | TObject *o = luaA_index(L, 1); | 250 | TObject *o = index(L, 1); |
249 | Table *t; | 251 | Table *t; |
250 | luaL_check_type(L, 2, LUA_TTABLE); | 252 | luaL_check_type(L, 2, LUA_TTABLE); |
251 | t = hvalue(luaA_index(L, 2)); | 253 | t = hvalue(index(L, 2)); |
252 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); | 254 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); |
253 | } | 255 | } |
254 | return 1; | 256 | return 1; |
@@ -270,7 +272,7 @@ static int table_query (lua_State *L) { | |||
270 | const Table *t; | 272 | const Table *t; |
271 | int i = luaL_opt_int(L, 2, -1); | 273 | int i = luaL_opt_int(L, 2, -1); |
272 | luaL_check_type(L, 1, LUA_TTABLE); | 274 | luaL_check_type(L, 1, LUA_TTABLE); |
273 | t = hvalue(luaA_index(L, 1)); | 275 | t = hvalue(index(L, 1)); |
274 | if (i == -1) { | 276 | if (i == -1) { |
275 | lua_pushnumber(L, t->sizearray); | 277 | lua_pushnumber(L, t->sizearray); |
276 | lua_pushnumber(L, sizenode(t)); | 278 | lua_pushnumber(L, sizenode(t)); |