aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-05 11:50:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-05 11:50:39 -0300
commit5037196f6fddb828056578b1c0d352cdef672d6a (patch)
treed1be52a5ad8fd5cebf30f7023a9c66b7bdc9563f
parent9fb80bde3c80557f8ad2d5642bcbeac343999994 (diff)
downloadlua-5037196f6fddb828056578b1c0d352cdef672d6a.tar.gz
lua-5037196f6fddb828056578b1c0d352cdef672d6a.tar.bz2
lua-5037196f6fddb828056578b1c0d352cdef672d6a.zip
new macros `ttis*'
-rw-r--r--lapi.c29
-rw-r--r--lcode.c6
-rw-r--r--lgc.c14
-rw-r--r--lobject.h31
-rw-r--r--ltable.c42
-rw-r--r--ltm.c4
6 files changed, 71 insertions, 55 deletions
diff --git a/lapi.c b/lapi.c
index ebb16a38..7d1831c8 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.204 2002/06/26 19:28:44 roberto Exp roberto $ 2** $Id: lapi.c,v 1.205 2002/07/17 16:25: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*/
@@ -266,7 +266,7 @@ LUA_API const char *lua_tostring (lua_State *L, int index) {
266 StkId o = luaA_indexAcceptable(L, index); 266 StkId o = luaA_indexAcceptable(L, index);
267 if (o == NULL) 267 if (o == NULL)
268 return NULL; 268 return NULL;
269 else if (ttype(o) == LUA_TSTRING) 269 else if (ttisstring(o))
270 return svalue(o); 270 return svalue(o);
271 else { 271 else {
272 const char *s; 272 const char *s;
@@ -282,7 +282,7 @@ LUA_API size_t lua_strlen (lua_State *L, int index) {
282 StkId o = luaA_indexAcceptable(L, index); 282 StkId o = luaA_indexAcceptable(L, index);
283 if (o == NULL) 283 if (o == NULL)
284 return 0; 284 return 0;
285 else if (ttype(o) == LUA_TSTRING) 285 else if (ttisstring(o))
286 return tsvalue(o)->tsv.len; 286 return tsvalue(o)->tsv.len;
287 else { 287 else {
288 size_t l; 288 size_t l;
@@ -439,7 +439,7 @@ LUA_API void lua_rawget (lua_State *L, int index) {
439 StkId t; 439 StkId t;
440 lua_lock(L); 440 lua_lock(L);
441 t = luaA_index(L, index); 441 t = luaA_index(L, index);
442 api_check(L, ttype(t) == LUA_TTABLE); 442 api_check(L, ttistable(t));
443 setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); 443 setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1));
444 lua_unlock(L); 444 lua_unlock(L);
445} 445}
@@ -449,7 +449,7 @@ LUA_API void lua_rawgeti (lua_State *L, int index, int n) {
449 StkId o; 449 StkId o;
450 lua_lock(L); 450 lua_lock(L);
451 o = luaA_index(L, index); 451 o = luaA_index(L, index);
452 api_check(L, ttype(o) == LUA_TTABLE); 452 api_check(L, ttistable(o));
453 setobj(L->top, luaH_getnum(hvalue(o), n)); 453 setobj(L->top, luaH_getnum(hvalue(o), n));
454 api_incr_top(L); 454 api_incr_top(L);
455 lua_unlock(L); 455 lua_unlock(L);
@@ -536,7 +536,7 @@ LUA_API void lua_rawset (lua_State *L, int index) {
536 lua_lock(L); 536 lua_lock(L);
537 api_checknelems(L, 2); 537 api_checknelems(L, 2);
538 t = luaA_index(L, index); 538 t = luaA_index(L, index);
539 api_check(L, ttype(t) == LUA_TTABLE); 539 api_check(L, ttistable(t));
540 setobj(luaH_set(L, hvalue(t), L->top-2), L->top-1); 540 setobj(luaH_set(L, hvalue(t), L->top-2), L->top-1);
541 L->top -= 2; 541 L->top -= 2;
542 lua_unlock(L); 542 lua_unlock(L);
@@ -548,7 +548,7 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) {
548 lua_lock(L); 548 lua_lock(L);
549 api_checknelems(L, 1); 549 api_checknelems(L, 1);
550 o = luaA_index(L, index); 550 o = luaA_index(L, index);
551 api_check(L, ttype(o) == LUA_TTABLE); 551 api_check(L, ttistable(o));
552 setobj(luaH_setnum(L, hvalue(o), n), L->top-1); 552 setobj(luaH_setnum(L, hvalue(o), n), L->top-1);
553 L->top--; 553 L->top--;
554 lua_unlock(L); 554 lua_unlock(L);
@@ -561,8 +561,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
561 lua_lock(L); 561 lua_lock(L);
562 api_checknelems(L, 1); 562 api_checknelems(L, 1);
563 obj = luaA_index(L, objindex); 563 obj = luaA_index(L, objindex);
564 mt = (ttype(L->top - 1) != LUA_TNIL) ? L->top - 1 : defaultmeta(L); 564 mt = (!ttisnil(L->top - 1)) ? L->top - 1 : defaultmeta(L);
565 api_check(L, ttype(mt) == LUA_TTABLE); 565 api_check(L, ttistable(mt));
566 switch (ttype(obj)) { 566 switch (ttype(obj)) {
567 case LUA_TTABLE: { 567 case LUA_TTABLE: {
568 hvalue(obj)->metatable = hvalue(mt); 568 hvalue(obj)->metatable = hvalue(mt);
@@ -589,7 +589,7 @@ LUA_API int lua_setglobals (lua_State *L, int level) {
589 api_checknelems(L, 1); 589 api_checknelems(L, 1);
590 f = getfunc(L, level); 590 f = getfunc(L, level);
591 L->top--; 591 L->top--;
592 api_check(L, ttype(L->top) == LUA_TTABLE); 592 api_check(L, ttistable(L->top));
593 if (f) f->g = *(L->top); 593 if (f) f->g = *(L->top);
594 lua_unlock(L); 594 lua_unlock(L);
595 return (f != NULL); 595 return (f != NULL);
@@ -619,6 +619,13 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults) {
619} 619}
620 620
621 621
622LUA_API void lua_pcallreset (lua_State *L) {
623 lua_lock(L);
624 luaD_resetprotection(L); /* reset error handler */
625 lua_unlock(L);
626}
627
628
622LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data, 629LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data,
623 const char *chunkname) { 630 const char *chunkname) {
624 ZIO z; 631 ZIO z;
@@ -688,7 +695,7 @@ LUA_API int lua_next (lua_State *L, int index) {
688 int more; 695 int more;
689 lua_lock(L); 696 lua_lock(L);
690 t = luaA_index(L, index); 697 t = luaA_index(L, index);
691 api_check(L, ttype(t) == LUA_TTABLE); 698 api_check(L, ttistable(t));
692 more = luaH_next(L, hvalue(t), L->top - 1); 699 more = luaH_next(L, hvalue(t), L->top - 1);
693 if (more) { 700 if (more) {
694 api_incr_top(L); 701 api_incr_top(L);
diff --git a/lcode.c b/lcode.c
index eadaef52..cd976cf0 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.107 2002/06/12 14:51:31 roberto Exp roberto $ 2** $Id: lcode.c,v 1.108 2002/06/13 13:39:55 roberto Exp $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -206,7 +206,7 @@ static void freeexp (FuncState *fs, expdesc *e) {
206 206
207static int addk (FuncState *fs, TObject *k, TObject *v) { 207static int addk (FuncState *fs, TObject *k, TObject *v) {
208 const TObject *index = luaH_get(fs->h, k); 208 const TObject *index = luaH_get(fs->h, k);
209 if (ttype(index) == LUA_TNUMBER) { 209 if (ttisnumber(index)) {
210 lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(index))], v)); 210 lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(index))], v));
211 return cast(int, nvalue(index)); 211 return cast(int, nvalue(index));
212 } 212 }
@@ -573,7 +573,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
573void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { 573void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
574 if (op == OPR_MINUS) { 574 if (op == OPR_MINUS) {
575 luaK_exp2val(fs, e); 575 luaK_exp2val(fs, e);
576 if (e->k == VK && ttype(&fs->f->k[e->info]) == LUA_TNUMBER) 576 if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
577 e->info = luaK_numberK(fs, -nvalue(&fs->f->k[e->info])); 577 e->info = luaK_numberK(fs, -nvalue(&fs->f->k[e->info]));
578 else { 578 else {
579 luaK_exp2anyreg(fs, e); 579 luaK_exp2anyreg(fs, e);
diff --git a/lgc.c b/lgc.c
index 47513769..3b2c3fa4 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.142 2002/07/08 18:21:33 roberto Exp roberto $ 2** $Id: lgc.c,v 1.143 2002/07/17 16:25:13 roberto Exp $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -71,7 +71,7 @@ static void protomark (Proto *f) {
71 f->marked = 1; 71 f->marked = 1;
72 strmark(f->source); 72 strmark(f->source);
73 for (i=0; i<f->sizek; i++) { 73 for (i=0; i<f->sizek; i++) {
74 if (ttype(f->k+i) == LUA_TSTRING) 74 if (ttisstring(f->k+i))
75 strmark(tsvalue(f->k+i)); 75 strmark(tsvalue(f->k+i));
76 } 76 }
77 for (i=0; i<f->sizep; i++) 77 for (i=0; i<f->sizep; i++)
@@ -148,7 +148,7 @@ static void checkstacksizes (lua_State *L, StkId max) {
148 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) 148 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
149 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ 149 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
150 used = max - L->stack; /* part of stack in use */ 150 used = max - L->stack; /* part of stack in use */
151 if (4*used < L->stacksize && 2*BASIC_STACK_SIZE < L->stacksize) 151 if (4*used < L->stacksize && 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
152 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ 152 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
153} 153}
154 154
@@ -158,7 +158,7 @@ static void markstacks (GCState *st) {
158 do { /* for each thread */ 158 do { /* for each thread */
159 StkId o, lim; 159 StkId o, lim;
160 CallInfo *ci; 160 CallInfo *ci;
161 if (L1->base_ci == NULL) { /* incomplete state? */ 161 if (ttisnil(defaultmeta(L1))) { /* incomplete state? */
162 lua_assert(L1 != st->L); 162 lua_assert(L1 != st->L);
163 L1 = L1->next; 163 L1 = L1->next;
164 luaE_closethread(st->L, L1->previous); /* collect it */ 164 luaE_closethread(st->L, L1->previous); /* collect it */
@@ -227,7 +227,7 @@ static void traversetable (GCState *st, Table *h) {
227 marktable(st, h->metatable); 227 marktable(st, h->metatable);
228 lua_assert(h->lsizenode || h->node == G(st->L)->dummynode); 228 lua_assert(h->lsizenode || h->node == G(st->L)->dummynode);
229 mode = fasttm(st->L, h->metatable, TM_MODE); 229 mode = fasttm(st->L, h->metatable, TM_MODE);
230 if (mode && ttype(mode) == LUA_TSTRING) { /* weak table? */ 230 if (mode && ttisstring(mode)) { /* weak table? */
231 h->mark = st->toclear; /* must be cleared after GC, ... */ 231 h->mark = st->toclear; /* must be cleared after GC, ... */
232 st->toclear = h; /* ...put in the appropriate list */ 232 st->toclear = h; /* ...put in the appropriate list */
233 weakkey = (strchr(svalue(mode), 'k') != NULL); 233 weakkey = (strchr(svalue(mode), 'k') != NULL);
@@ -243,8 +243,8 @@ static void traversetable (GCState *st, Table *h) {
243 i = sizenode(h); 243 i = sizenode(h);
244 while (i--) { 244 while (i--) {
245 Node *n = node(h, i); 245 Node *n = node(h, i);
246 if (ttype(val(n)) != LUA_TNIL) { 246 if (!ttisnil(val(n))) {
247 lua_assert(ttype(key(n)) != LUA_TNIL); 247 lua_assert(!ttisnil(key(n)));
248 if (!weakkey) markobject(st, key(n)); 248 if (!weakkey) markobject(st, key(n));
249 if (!weakvalue) markobject(st, val(n)); 249 if (!weakvalue) markobject(st, val(n));
250 } 250 }
diff --git a/lobject.h b/lobject.h
index 0e800c16..e3dc6f95 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.139 2002/07/01 17:06:58 roberto Exp roberto $ 2** $Id: lobject.h,v 1.140 2002/07/17 16:25:13 roberto Exp $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -33,18 +33,27 @@ typedef struct lua_TObject {
33} TObject; 33} TObject;
34 34
35 35
36/* Macros to test type */
37#define ttisnil(o) (ttype(o) == LUA_TNIL)
38#define ttisnumber(o) (ttype(o) == LUA_TNUMBER)
39#define ttisstring(o) (ttype(o) == LUA_TSTRING)
40#define ttistable(o) (ttype(o) == LUA_TTABLE)
41#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
42#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
43#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
44#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
45
36/* Macros to access values */ 46/* Macros to access values */
37#define ttype(o) ((o)->tt) 47#define ttype(o) ((o)->tt)
38#define pvalue(o) check_exp(ttype(o)==LUA_TLIGHTUSERDATA, (o)->value.p) 48#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
39#define nvalue(o) check_exp(ttype(o)==LUA_TNUMBER, (o)->value.n) 49#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
40#define tsvalue(o) check_exp(ttype(o)==LUA_TSTRING, (o)->value.ts) 50#define tsvalue(o) check_exp(ttisstring(o), (o)->value.ts)
41#define uvalue(o) check_exp(ttype(o)==LUA_TUSERDATA, (o)->value.u) 51#define uvalue(o) check_exp(ttisuserdata(o), (o)->value.u)
42#define clvalue(o) check_exp(ttype(o)==LUA_TFUNCTION, (o)->value.cl) 52#define clvalue(o) check_exp(ttisfunction(o), (o)->value.cl)
43#define hvalue(o) check_exp(ttype(o)==LUA_TTABLE, (o)->value.h) 53#define hvalue(o) check_exp(ttistable(o), (o)->value.h)
44#define bvalue(o) check_exp(ttype(o)==LUA_TBOOLEAN, (o)->value.b) 54#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
45 55
46#define l_isfalse(o) (ttype(o) == LUA_TNIL || \ 56#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
47 (ttype(o) == LUA_TBOOLEAN && bvalue(o) == 0))
48 57
49/* Macros to set values */ 58/* Macros to set values */
50#define setnvalue(obj,x) \ 59#define setnvalue(obj,x) \
diff --git a/ltable.c b/ltable.c
index 2951def0..576c615e 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.113 2002/07/02 17:54:23 roberto Exp roberto $ 2** $Id: ltable.c,v 1.114 2002/07/17 16:25:13 roberto Exp $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -99,7 +99,7 @@ Node *luaH_mainposition (const Table *t, const TObject *key) {
99** the array part of the table, -1 otherwise. 99** the array part of the table, -1 otherwise.
100*/ 100*/
101static int arrayindex (const TObject *key) { 101static int arrayindex (const TObject *key) {
102 if (ttype(key) == LUA_TNUMBER) { 102 if (ttisnumber(key)) {
103 int k; 103 int k;
104 lua_number2int(k, (nvalue(key))); 104 lua_number2int(k, (nvalue(key)));
105 if (cast(lua_Number, k) == nvalue(key) && k >= 1 && !toobig(k)) 105 if (cast(lua_Number, k) == nvalue(key) && k >= 1 && !toobig(k))
@@ -116,7 +116,7 @@ static int arrayindex (const TObject *key) {
116*/ 116*/
117static int luaH_index (lua_State *L, Table *t, const TObject *key) { 117static int luaH_index (lua_State *L, Table *t, const TObject *key) {
118 int i; 118 int i;
119 if (ttype(key) == LUA_TNIL) return -1; /* first iteration */ 119 if (ttisnil(key)) return -1; /* first iteration */
120 i = arrayindex(key); 120 i = arrayindex(key);
121 if (0 <= i && i <= t->sizearray) { /* is `key' inside array part? */ 121 if (0 <= i && i <= t->sizearray) { /* is `key' inside array part? */
122 return i-1; /* yes; that's the index (corrected to C) */ 122 return i-1; /* yes; that's the index (corrected to C) */
@@ -135,14 +135,14 @@ static int luaH_index (lua_State *L, Table *t, const TObject *key) {
135int luaH_next (lua_State *L, Table *t, TObject *key) { 135int luaH_next (lua_State *L, Table *t, TObject *key) {
136 int i = luaH_index(L, t, key); /* find original element */ 136 int i = luaH_index(L, t, key); /* find original element */
137 for (i++; i < t->sizearray; i++) { /* try first array part */ 137 for (i++; i < t->sizearray; i++) { /* try first array part */
138 if (ttype(&t->array[i]) != LUA_TNIL) { /* a non-nil value? */ 138 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
139 setnvalue(key, i+1); 139 setnvalue(key, i+1);
140 setobj(key+1, &t->array[i]); 140 setobj(key+1, &t->array[i]);
141 return 1; 141 return 1;
142 } 142 }
143 } 143 }
144 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ 144 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
145 if (ttype(val(node(t, i))) != LUA_TNIL) { /* a non-nil value? */ 145 if (!ttisnil(val(node(t, i)))) { /* a non-nil value? */
146 setobj(key, key(node(t, i))); 146 setobj(key, key(node(t, i)));
147 setobj(key+1, val(node(t, i))); 147 setobj(key+1, val(node(t, i)));
148 return 1; 148 return 1;
@@ -192,7 +192,7 @@ static void numuse (const Table *t, int *narray, int *nhash) {
192 int from = to/2; 192 int from = to/2;
193 if (to > t->sizearray) to = t->sizearray; 193 if (to > t->sizearray) to = t->sizearray;
194 for (; from < to; from++) 194 for (; from < to; from++)
195 if (ttype(&t->array[from]) != LUA_TNIL) { 195 if (!ttisnil(&t->array[from])) {
196 nums[i]++; 196 nums[i]++;
197 totaluse++; 197 totaluse++;
198 } 198 }
@@ -201,7 +201,7 @@ static void numuse (const Table *t, int *narray, int *nhash) {
201 /* count elements in hash part */ 201 /* count elements in hash part */
202 i = sizenode(t); 202 i = sizenode(t);
203 while (i--) { 203 while (i--) {
204 if (ttype(val(&t->node[i])) != LUA_TNIL) { 204 if (!ttisnil(val(&t->node[i]))) {
205 int k = arrayindex(key(&t->node[i])); 205 int k = arrayindex(key(&t->node[i]));
206 if (k >= 0) { /* is `key' an appropriate array index? */ 206 if (k >= 0) { /* is `key' an appropriate array index? */
207 nums[luaO_log2(k-1)+1]++; /* count as such */ 207 nums[luaO_log2(k-1)+1]++; /* count as such */
@@ -230,8 +230,8 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
230 luaG_runerror(L, "table overflow"); 230 luaG_runerror(L, "table overflow");
231 if (lsize == 0) { /* no elements to hash part? */ 231 if (lsize == 0) { /* no elements to hash part? */
232 t->node = G(L)->dummynode; /* use common `dummynode' */ 232 t->node = G(L)->dummynode; /* use common `dummynode' */
233 lua_assert(ttype(key(t->node)) == LUA_TNIL); /* assert invariants: */ 233 lua_assert(ttisnil(key(t->node))); /* assert invariants: */
234 lua_assert(ttype(val(t->node)) == LUA_TNIL); 234 lua_assert(ttisnil(val(t->node)));
235 lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */ 235 lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */
236 } 236 }
237 else { 237 else {
@@ -272,7 +272,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
272 t->sizearray = nasize; 272 t->sizearray = nasize;
273 /* re-insert elements from vanishing slice */ 273 /* re-insert elements from vanishing slice */
274 for (i=nasize; i<oldasize; i++) { 274 for (i=nasize; i<oldasize; i++) {
275 if (ttype(&t->array[i]) != LUA_TNIL) 275 if (!ttisnil(&t->array[i]))
276 setobj(luaH_setnum(L, t, i+1), &t->array[i]); 276 setobj(luaH_setnum(L, t, i+1), &t->array[i]);
277 } 277 }
278 /* shrink array */ 278 /* shrink array */
@@ -281,7 +281,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
281 /* re-insert elements in hash part */ 281 /* re-insert elements in hash part */
282 for (i = twoto(oldhsize) - 1; i >= 0; i--) { 282 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
283 Node *old = nold+i; 283 Node *old = nold+i;
284 if (ttype(val(old)) != LUA_TNIL) 284 if (!ttisnil(val(old)))
285 setobj(luaH_set(L, t, key(old)), val(old)); 285 setobj(luaH_set(L, t, key(old)), val(old));
286 } 286 }
287 if (oldhsize) 287 if (oldhsize)
@@ -342,7 +342,7 @@ void luaH_remove (Table *t, Node *e) {
342 else { 342 else {
343 if (e->next != NULL) ?? 343 if (e->next != NULL) ??
344 } 344 }
345 lua_assert(ttype(val(node)) == LUA_TNIL); 345 lua_assert(ttisnil(val(node)));
346 setnilvalue(key(e)); /* clear node `e' */ 346 setnilvalue(key(e)); /* clear node `e' */
347 e->next = NULL; 347 e->next = NULL;
348} 348}
@@ -359,7 +359,7 @@ void luaH_remove (Table *t, Node *e) {
359static TObject *newkey (lua_State *L, Table *t, const TObject *key) { 359static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
360 TObject *val; 360 TObject *val;
361 Node *mp = luaH_mainposition(t, key); 361 Node *mp = luaH_mainposition(t, key);
362 if (ttype(val(mp)) != LUA_TNIL) { /* main position is not free? */ 362 if (!ttisnil(val(mp))) { /* main position is not free? */
363 Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */ 363 Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */
364 Node *n = t->firstfree; /* get a free place */ 364 Node *n = t->firstfree; /* get a free place */
365 if (othern != mp) { /* is colliding node out of its main position? */ 365 if (othern != mp) { /* is colliding node out of its main position? */
@@ -378,9 +378,9 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
378 } 378 }
379 } 379 }
380 setobj(key(mp), key); 380 setobj(key(mp), key);
381 lua_assert(ttype(val(mp)) == LUA_TNIL); 381 lua_assert(ttisnil(val(mp)));
382 for (;;) { /* correct `firstfree' */ 382 for (;;) { /* correct `firstfree' */
383 if (ttype(key(t->firstfree)) == LUA_TNIL) 383 if (ttisnil(key(t->firstfree)))
384 return val(mp); /* OK; table still has a free place */ 384 return val(mp); /* OK; table still has a free place */
385 else if (t->firstfree == t->node) break; /* cannot decrement from here */ 385 else if (t->firstfree == t->node) break; /* cannot decrement from here */
386 else (t->firstfree)--; 386 else (t->firstfree)--;
@@ -389,7 +389,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
389 setbvalue(val(mp), 0); /* avoid new key being removed */ 389 setbvalue(val(mp), 0); /* avoid new key being removed */
390 rehash(L, t); /* grow table */ 390 rehash(L, t); /* grow table */
391 val = cast(TObject *, luaH_get(t, key)); /* get new position */ 391 val = cast(TObject *, luaH_get(t, key)); /* get new position */
392 lua_assert(ttype(val) == LUA_TBOOLEAN); 392 lua_assert(ttisboolean(val));
393 setnilvalue(val); 393 setnilvalue(val);
394 return val; 394 return val;
395} 395}
@@ -399,7 +399,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
399** generic search function 399** generic search function
400*/ 400*/
401static const TObject *luaH_getany (Table *t, const TObject *key) { 401static const TObject *luaH_getany (Table *t, const TObject *key) {
402 if (ttype(key) == LUA_TNIL) return &luaO_nilobject; 402 if (ttisnil(key)) return &luaO_nilobject;
403 else { 403 else {
404 Node *n = luaH_mainposition(t, key); 404 Node *n = luaH_mainposition(t, key);
405 do { /* check whether `key' is somewhere in the chain */ 405 do { /* check whether `key' is somewhere in the chain */
@@ -420,7 +420,7 @@ const TObject *luaH_getnum (Table *t, int key) {
420 else { 420 else {
421 Node *n = hashnum(t, key); 421 Node *n = hashnum(t, key);
422 do { /* check whether `key' is somewhere in the chain */ 422 do { /* check whether `key' is somewhere in the chain */
423 if (ttype(key(n)) == LUA_TNUMBER && nvalue(key(n)) == (lua_Number)key) 423 if (ttisnumber(key(n)) && nvalue(key(n)) == (lua_Number)key)
424 return val(n); /* that's it */ 424 return val(n); /* that's it */
425 else n = n->next; 425 else n = n->next;
426 } while (n); 426 } while (n);
@@ -435,7 +435,7 @@ const TObject *luaH_getnum (Table *t, int key) {
435const TObject *luaH_getstr (Table *t, TString *key) { 435const TObject *luaH_getstr (Table *t, TString *key) {
436 Node *n = hashstr(t, key); 436 Node *n = hashstr(t, key);
437 do { /* check whether `key' is somewhere in the chain */ 437 do { /* check whether `key' is somewhere in the chain */
438 if (ttype(key(n)) == LUA_TSTRING && tsvalue(key(n)) == key) 438 if (ttisstring(key(n)) && tsvalue(key(n)) == key)
439 return val(n); /* that's it */ 439 return val(n); /* that's it */
440 else n = n->next; 440 else n = n->next;
441 } while (n); 441 } while (n);
@@ -467,8 +467,8 @@ TObject *luaH_set (lua_State *L, Table *t, const TObject *key) {
467 if (p != &luaO_nilobject) 467 if (p != &luaO_nilobject)
468 return cast(TObject *, p); 468 return cast(TObject *, p);
469 else { 469 else {
470 if (ttype(key) == LUA_TNIL) luaG_runerror(L, "table index is nil"); 470 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
471 else if (ttype(key) == LUA_TNUMBER && nvalue(key) != nvalue(key)) 471 else if (ttisnumber(key) && nvalue(key) != nvalue(key))
472 luaG_runerror(L, "table index is NaN"); 472 luaG_runerror(L, "table index is NaN");
473 return newkey(L, t, key); 473 return newkey(L, t, key);
474 } 474 }
diff --git a/ltm.c b/ltm.c
index d9a8dcac..70fd9807 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.97 2002/06/25 19:17:22 roberto Exp roberto $ 2** $Id: ltm.c,v 1.98 2002/07/17 16:25:13 roberto Exp $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -47,7 +47,7 @@ void luaT_init (lua_State *L) {
47const TObject *luaT_gettm (Table *events, TMS event, TString *ename) { 47const TObject *luaT_gettm (Table *events, TMS event, TString *ename) {
48 const TObject *tm = luaH_getstr(events, ename); 48 const TObject *tm = luaH_getstr(events, ename);
49 lua_assert(event <= TM_MODE); 49 lua_assert(event <= TM_MODE);
50 if (ttype(tm) == LUA_TNIL) { /* no tag method? */ 50 if (ttisnil(tm)) { /* no tag method? */
51 events->flags |= (1u<<event); /* cache this fact */ 51 events->flags |= (1u<<event); /* cache this fact */
52 return NULL; 52 return NULL;
53 } 53 }