diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 09:14:08 -0300 |
commit | 001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch) | |
tree | d200cf4d708be3c61e64640c45b47050c9c6a375 | |
parent | cd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff) | |
download | lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2 lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip |
new definition for types-tags
-rw-r--r-- | lapi.c | 77 | ||||
-rw-r--r-- | lauxlib.c | 8 | ||||
-rw-r--r-- | lauxlib.h | 4 | ||||
-rw-r--r-- | lbaselib.c | 4 | ||||
-rw-r--r-- | ldebug.c | 79 | ||||
-rw-r--r-- | ldebug.h | 4 | ||||
-rw-r--r-- | ldo.c | 56 | ||||
-rw-r--r-- | lgc.c | 60 | ||||
-rw-r--r-- | lobject.c | 25 | ||||
-rw-r--r-- | lobject.h | 55 | ||||
-rw-r--r-- | lstrlib.c | 4 | ||||
-rw-r--r-- | ltable.c | 48 | ||||
-rw-r--r-- | ltests.c | 15 | ||||
-rw-r--r-- | ltm.c | 49 | ||||
-rw-r--r-- | ltm.h | 9 | ||||
-rw-r--r-- | lua.h | 23 | ||||
-rw-r--r-- | lvm.c | 112 | ||||
-rw-r--r-- | lvm.h | 6 |
18 files changed, 307 insertions, 331 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.103 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.104 2000/10/03 14:27:44 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 | */ |
@@ -116,20 +116,18 @@ void lua_pushvalue (lua_State *L, int index) { | |||
116 | return ((test) ? (value) : (default)); } | 116 | return ((test) ? (value) : (default)); } |
117 | 117 | ||
118 | 118 | ||
119 | lua_Type lua_type (lua_State *L, int index) { | 119 | int lua_type (lua_State *L, int index) { |
120 | btest(L, index, luaO_type(o), LUA_NOVALUE); | 120 | btest(L, index, ttype(o), LUA_TNONE); |
121 | } | 121 | } |
122 | 122 | ||
123 | const char *lua_typename (lua_State *L, lua_Type t) { | 123 | const char *lua_typename (lua_State *L, int t) { |
124 | static const char *const names[] = { | ||
125 | "NO VALUE", "userdata", "number", "string", "table", "function", "nil" | ||
126 | }; | ||
127 | UNUSED(L); | 124 | UNUSED(L); |
128 | return names[(int)t]; | 125 | return luaO_typenames[t]; |
129 | } | 126 | } |
130 | 127 | ||
128 | |||
131 | int lua_iscfunction (lua_State *L, int index) { | 129 | int lua_iscfunction (lua_State *L, int index) { |
132 | btest(L, index, (ttype(o) == TAG_CCLOSURE), 0); | 130 | btest(L, index, iscfunction(o), 0); |
133 | } | 131 | } |
134 | 132 | ||
135 | int lua_isnumber (lua_State *L, int index) { | 133 | int lua_isnumber (lua_State *L, int index) { |
@@ -137,18 +135,13 @@ int lua_isnumber (lua_State *L, int index) { | |||
137 | } | 135 | } |
138 | 136 | ||
139 | int lua_isstring (lua_State *L, int index) { | 137 | int lua_isstring (lua_State *L, int index) { |
140 | lua_Type t = lua_type(L, index); | 138 | int t = lua_type(L, index); |
141 | return (t == LUA_TSTRING || t == LUA_TNUMBER); | 139 | return (t == LUA_TSTRING || t == LUA_TNUMBER); |
142 | } | 140 | } |
143 | 141 | ||
144 | 142 | ||
145 | static int auxtag (const TObject *o) { | ||
146 | return ((ttype(o) == TAG_USERDATA) ? tsvalue(o)->u.d.tag : | ||
147 | (ttype(o) == TAG_TABLE) ? hvalue(o)->htag : (int)ttype(o)); | ||
148 | } | ||
149 | |||
150 | int lua_tag (lua_State *L, int index) { | 143 | int lua_tag (lua_State *L, int index) { |
151 | btest(L, index, auxtag(o), LUA_NOTAG); | 144 | btest(L, index, luaT_tag(o), LUA_NOTAG); |
152 | } | 145 | } |
153 | 146 | ||
154 | int lua_equal (lua_State *L, int index1, int index2) { | 147 | int lua_equal (lua_State *L, int index1, int index2) { |
@@ -168,7 +161,7 @@ int lua_lessthan (lua_State *L, int index1, int index2) { | |||
168 | 161 | ||
169 | 162 | ||
170 | double lua_tonumber (lua_State *L, int index) { | 163 | double lua_tonumber (lua_State *L, int index) { |
171 | access(L, index, (tonumber(o) == 0), 0.0, nvalue(o)); | 164 | access(L, index, (tonumber(o) == 0), 0, nvalue(o)); |
172 | } | 165 | } |
173 | 166 | ||
174 | const char *lua_tostring (lua_State *L, int index) { | 167 | const char *lua_tostring (lua_State *L, int index) { |
@@ -180,19 +173,19 @@ size_t lua_strlen (lua_State *L, int index) { | |||
180 | } | 173 | } |
181 | 174 | ||
182 | lua_CFunction lua_tocfunction (lua_State *L, int index) { | 175 | lua_CFunction lua_tocfunction (lua_State *L, int index) { |
183 | access(L, index, (ttype(o) == TAG_CCLOSURE), NULL, clvalue(o)->f.c); | 176 | access(L, index, iscfunction(o), NULL, clvalue(o)->f.c); |
184 | } | 177 | } |
185 | 178 | ||
186 | void *lua_touserdata (lua_State *L, int index) { | 179 | void *lua_touserdata (lua_State *L, int index) { |
187 | access(L, index, (ttype(o) == TAG_USERDATA), NULL, tsvalue(o)->u.d.value); | 180 | access(L, index, (ttype(o) == LUA_TUSERDATA), NULL, tsvalue(o)->u.d.value); |
188 | } | 181 | } |
189 | 182 | ||
190 | const void *lua_topointer (lua_State *L, int index) { | 183 | const void *lua_topointer (lua_State *L, int index) { |
191 | StkId o = Index(L, index); | 184 | StkId o = Index(L, index); |
192 | switch (ttype(o)) { | 185 | switch (ttype(o)) { |
193 | case TAG_TABLE: | 186 | case LUA_TTABLE: |
194 | return hvalue(o); | 187 | return hvalue(o); |
195 | case TAG_CCLOSURE: case TAG_LCLOSURE: | 188 | case LUA_TFUNCTION: |
196 | return clvalue(o); | 189 | return clvalue(o); |
197 | default: return NULL; | 190 | default: return NULL; |
198 | } | 191 | } |
@@ -206,13 +199,13 @@ const void *lua_topointer (lua_State *L, int index) { | |||
206 | 199 | ||
207 | 200 | ||
208 | void lua_pushnil (lua_State *L) { | 201 | void lua_pushnil (lua_State *L) { |
209 | ttype(L->top) = TAG_NIL; | 202 | ttype(L->top) = LUA_TNIL; |
210 | api_incr_top(L); | 203 | api_incr_top(L); |
211 | } | 204 | } |
212 | 205 | ||
213 | 206 | ||
214 | void lua_pushnumber (lua_State *L, double n) { | 207 | void lua_pushnumber (lua_State *L, double n) { |
215 | ttype(L->top) = TAG_NUMBER; | 208 | ttype(L->top) = LUA_TNUMBER; |
216 | nvalue(L->top) = n; | 209 | nvalue(L->top) = n; |
217 | api_incr_top(L); | 210 | api_incr_top(L); |
218 | } | 211 | } |
@@ -220,7 +213,7 @@ void lua_pushnumber (lua_State *L, double n) { | |||
220 | 213 | ||
221 | void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 214 | void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
222 | tsvalue(L->top) = luaS_newlstr(L, s, len); | 215 | tsvalue(L->top) = luaS_newlstr(L, s, len); |
223 | ttype(L->top) = TAG_STRING; | 216 | ttype(L->top) = LUA_TSTRING; |
224 | api_incr_top(L); | 217 | api_incr_top(L); |
225 | } | 218 | } |
226 | 219 | ||
@@ -239,10 +232,10 @@ void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
239 | 232 | ||
240 | 233 | ||
241 | void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */ | 234 | void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */ |
242 | if (tag != LUA_ANYTAG && tag != TAG_USERDATA && tag < NUM_TAGS) | 235 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) |
243 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 236 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
244 | tsvalue(L->top) = luaS_createudata(L, u, tag); | 237 | tsvalue(L->top) = luaS_createudata(L, u, tag); |
245 | ttype(L->top) = TAG_USERDATA; | 238 | ttype(L->top) = LUA_TUSERDATA; |
246 | api_incr_top(L); | 239 | api_incr_top(L); |
247 | } | 240 | } |
248 | 241 | ||
@@ -271,14 +264,14 @@ void lua_gettable (lua_State *L, int index) { | |||
271 | 264 | ||
272 | void lua_rawget (lua_State *L, int index) { | 265 | void lua_rawget (lua_State *L, int index) { |
273 | StkId t = Index(L, index); | 266 | StkId t = Index(L, index); |
274 | LUA_ASSERT(ttype(t) == TAG_TABLE, "table expected"); | 267 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
275 | *(L->top - 1) = *luaH_get(L, hvalue(t), L->top - 1); | 268 | *(L->top - 1) = *luaH_get(L, hvalue(t), L->top - 1); |
276 | } | 269 | } |
277 | 270 | ||
278 | 271 | ||
279 | void lua_rawgeti (lua_State *L, int index, int n) { | 272 | void lua_rawgeti (lua_State *L, int index, int n) { |
280 | StkId o = Index(L, index); | 273 | StkId o = Index(L, index); |
281 | LUA_ASSERT(ttype(o) == TAG_TABLE, "table expected"); | 274 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
282 | *L->top = *luaH_getnum(hvalue(o), n); | 275 | *L->top = *luaH_getnum(hvalue(o), n); |
283 | api_incr_top(L); | 276 | api_incr_top(L); |
284 | } | 277 | } |
@@ -286,14 +279,14 @@ void lua_rawgeti (lua_State *L, int index, int n) { | |||
286 | 279 | ||
287 | void lua_getglobals (lua_State *L) { | 280 | void lua_getglobals (lua_State *L) { |
288 | hvalue(L->top) = L->gt; | 281 | hvalue(L->top) = L->gt; |
289 | ttype(L->top) = TAG_TABLE; | 282 | ttype(L->top) = LUA_TTABLE; |
290 | api_incr_top(L); | 283 | api_incr_top(L); |
291 | } | 284 | } |
292 | 285 | ||
293 | 286 | ||
294 | int lua_getref (lua_State *L, int ref) { | 287 | int lua_getref (lua_State *L, int ref) { |
295 | if (ref == LUA_REFNIL) | 288 | if (ref == LUA_REFNIL) |
296 | ttype(L->top) = TAG_NIL; | 289 | ttype(L->top) = LUA_TNIL; |
297 | else if (0 <= ref && ref < L->refSize && | 290 | else if (0 <= ref && ref < L->refSize && |
298 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) | 291 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) |
299 | *L->top = L->refArray[ref].o; | 292 | *L->top = L->refArray[ref].o; |
@@ -306,7 +299,7 @@ int lua_getref (lua_State *L, int ref) { | |||
306 | 299 | ||
307 | void lua_newtable (lua_State *L) { | 300 | void lua_newtable (lua_State *L) { |
308 | hvalue(L->top) = luaH_new(L, 0); | 301 | hvalue(L->top) = luaH_new(L, 0); |
309 | ttype(L->top) = TAG_TABLE; | 302 | ttype(L->top) = LUA_TTABLE; |
310 | api_incr_top(L); | 303 | api_incr_top(L); |
311 | } | 304 | } |
312 | 305 | ||
@@ -334,7 +327,7 @@ void lua_settable (lua_State *L, int index) { | |||
334 | 327 | ||
335 | void lua_rawset (lua_State *L, int index) { | 328 | void lua_rawset (lua_State *L, int index) { |
336 | StkId t = Index(L, index); | 329 | StkId t = Index(L, index); |
337 | LUA_ASSERT(ttype(t) == TAG_TABLE, "table expected"); | 330 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
338 | *luaH_set(L, hvalue(t), L->top-2) = *(L->top-1); | 331 | *luaH_set(L, hvalue(t), L->top-2) = *(L->top-1); |
339 | L->top -= 2; | 332 | L->top -= 2; |
340 | } | 333 | } |
@@ -342,7 +335,7 @@ void lua_rawset (lua_State *L, int index) { | |||
342 | 335 | ||
343 | void lua_rawseti (lua_State *L, int index, int n) { | 336 | void lua_rawseti (lua_State *L, int index, int n) { |
344 | StkId o = Index(L, index); | 337 | StkId o = Index(L, index); |
345 | LUA_ASSERT(ttype(o) == TAG_TABLE, "table expected"); | 338 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
346 | *luaH_setint(L, hvalue(o), n) = *(L->top-1); | 339 | *luaH_setint(L, hvalue(o), n) = *(L->top-1); |
347 | L->top--; | 340 | L->top--; |
348 | } | 341 | } |
@@ -350,14 +343,14 @@ void lua_rawseti (lua_State *L, int index, int n) { | |||
350 | 343 | ||
351 | void lua_setglobals (lua_State *L) { | 344 | void lua_setglobals (lua_State *L) { |
352 | StkId newtable = --L->top; | 345 | StkId newtable = --L->top; |
353 | LUA_ASSERT(ttype(newtable) == TAG_TABLE, "table expected"); | 346 | LUA_ASSERT(ttype(newtable) == LUA_TTABLE, "table expected"); |
354 | L->gt = hvalue(newtable); | 347 | L->gt = hvalue(newtable); |
355 | } | 348 | } |
356 | 349 | ||
357 | 350 | ||
358 | int lua_ref (lua_State *L, int lock) { | 351 | int lua_ref (lua_State *L, int lock) { |
359 | int ref; | 352 | int ref; |
360 | if (ttype(L->top-1) == TAG_NIL) | 353 | if (ttype(L->top-1) == LUA_TNIL) |
361 | ref = LUA_REFNIL; | 354 | ref = LUA_REFNIL; |
362 | else { | 355 | else { |
363 | if (L->refFree != NONEXT) { /* is there a free place? */ | 356 | if (L->refFree != NONEXT) { /* is there a free place? */ |
@@ -420,15 +413,15 @@ void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
420 | void lua_settag (lua_State *L, int tag) { | 413 | void lua_settag (lua_State *L, int tag) { |
421 | luaT_realtag(L, tag); | 414 | luaT_realtag(L, tag); |
422 | switch (ttype(L->top-1)) { | 415 | switch (ttype(L->top-1)) { |
423 | case TAG_TABLE: | 416 | case LUA_TTABLE: |
424 | hvalue(L->top-1)->htag = tag; | 417 | hvalue(L->top-1)->htag = tag; |
425 | break; | 418 | break; |
426 | case TAG_USERDATA: | 419 | case LUA_TUSERDATA: |
427 | tsvalue(L->top-1)->u.d.tag = tag; | 420 | tsvalue(L->top-1)->u.d.tag = tag; |
428 | break; | 421 | break; |
429 | default: | 422 | default: |
430 | luaO_verror(L, "cannot change the tag of a %.20s", | 423 | luaO_verror(L, "cannot change the tag of a %.20s", |
431 | luaO_typename(L, L->top-1)); | 424 | luaO_typename(L->top-1)); |
432 | } | 425 | } |
433 | L->top--; | 426 | L->top--; |
434 | } | 427 | } |
@@ -446,7 +439,7 @@ void lua_unref (lua_State *L, int ref) { | |||
446 | int lua_next (lua_State *L, int index) { | 439 | int lua_next (lua_State *L, int index) { |
447 | StkId t = Index(L, index); | 440 | StkId t = Index(L, index); |
448 | Node *n; | 441 | Node *n; |
449 | LUA_ASSERT(ttype(t) == TAG_TABLE, "table expected"); | 442 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
450 | n = luaH_next(L, hvalue(t), Index(L, -1)); | 443 | n = luaH_next(L, hvalue(t), Index(L, -1)); |
451 | if (n) { | 444 | if (n) { |
452 | *(L->top-1) = *key(n); | 445 | *(L->top-1) = *key(n); |
@@ -464,15 +457,15 @@ int lua_next (lua_State *L, int index) { | |||
464 | int lua_getn (lua_State *L, int index) { | 457 | int lua_getn (lua_State *L, int index) { |
465 | Hash *h = hvalue(Index(L, index)); | 458 | Hash *h = hvalue(Index(L, index)); |
466 | const TObject *value = luaH_getstr(h, luaS_new(L, "n")); /* value = h.n */ | 459 | const TObject *value = luaH_getstr(h, luaS_new(L, "n")); /* value = h.n */ |
467 | if (ttype(value) == TAG_NUMBER) | 460 | if (ttype(value) == LUA_TNUMBER) |
468 | return (int)nvalue(value); | 461 | return (int)nvalue(value); |
469 | else { | 462 | else { |
470 | Number max = 0; | 463 | Number max = 0; |
471 | int i = h->size; | 464 | int i = h->size; |
472 | Node *n = h->node; | 465 | Node *n = h->node; |
473 | while (i--) { | 466 | while (i--) { |
474 | if (ttype(key(n)) == TAG_NUMBER && | 467 | if (ttype(key(n)) == LUA_TNUMBER && |
475 | ttype(val(n)) != TAG_NIL && | 468 | ttype(val(n)) != LUA_TNIL && |
476 | nvalue(key(n)) > max) | 469 | nvalue(key(n)) > max) |
477 | max = nvalue(key(n)); | 470 | max = nvalue(key(n)); |
478 | n++; | 471 | n++; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.37 2000/09/29 12:40:56 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.38 2000/10/02 20:10:55 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 | */ |
@@ -40,7 +40,7 @@ void luaL_argerror (lua_State *L, int narg, const char *extramsg) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | 42 | ||
43 | static void type_error (lua_State *L, int narg, lua_Type t) { | 43 | static void type_error (lua_State *L, int narg, int t) { |
44 | char buff[100]; | 44 | char buff[100]; |
45 | const char *rt = lua_typename(L, lua_type(L, narg)); | 45 | const char *rt = lua_typename(L, lua_type(L, narg)); |
46 | if (*rt == 'N') rt = "no value"; | 46 | if (*rt == 'N') rt = "no value"; |
@@ -55,14 +55,14 @@ void luaL_checkstack (lua_State *L, int space, const char *mes) { | |||
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | void luaL_checktype(lua_State *L, int narg, lua_Type t) { | 58 | void luaL_checktype(lua_State *L, int narg, int t) { |
59 | if (lua_type(L, narg) != t) | 59 | if (lua_type(L, narg) != t) |
60 | type_error(L, narg, t); | 60 | type_error(L, narg, t); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | void luaL_checkany (lua_State *L, int narg) { | 64 | void luaL_checkany (lua_State *L, int narg) { |
65 | if (lua_type(L, narg) == LUA_NOVALUE) | 65 | if (lua_type(L, narg) == LUA_TNONE) |
66 | luaL_argerror(L, narg, "value expected"); | 66 | luaL_argerror(L, narg, "value expected"); |
67 | } | 67 | } |
68 | 68 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.25 2000/09/12 13:48:22 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.26 2000/10/02 20:10:55 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 | */ |
@@ -30,7 +30,7 @@ double luaL_check_number (lua_State *L, int numArg); | |||
30 | double luaL_opt_number (lua_State *L, int numArg, double def); | 30 | double luaL_opt_number (lua_State *L, int numArg, double def); |
31 | 31 | ||
32 | void luaL_checkstack (lua_State *L, int space, const char *msg); | 32 | void luaL_checkstack (lua_State *L, int space, const char *msg); |
33 | void luaL_checktype (lua_State *L, int narg, lua_Type t); | 33 | void luaL_checktype (lua_State *L, int narg, int t); |
34 | void luaL_checkany (lua_State *L, int narg); | 34 | void luaL_checkany (lua_State *L, int narg); |
35 | 35 | ||
36 | void luaL_verror (lua_State *L, const char *fmt, ...); | 36 | void luaL_verror (lua_State *L, const char *fmt, ...); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.7 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.8 2000/10/02 20:10:55 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -322,7 +322,7 @@ static int luaB_tostring (lua_State *L) { | |||
322 | case LUA_TNIL: | 322 | case LUA_TNIL: |
323 | lua_pushstring(L, "nil"); | 323 | lua_pushstring(L, "nil"); |
324 | return 1; | 324 | return 1; |
325 | case LUA_NOVALUE: | 325 | default: |
326 | luaL_argerror(L, 1, "value expected"); | 326 | luaL_argerror(L, 1, "value expected"); |
327 | } | 327 | } |
328 | lua_pushstring(L, buff); | 328 | lua_pushstring(L, buff); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.42 2000/09/18 19:39:49 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.43 2000/10/02 20:10:55 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,23 +23,21 @@ | |||
23 | #include "luadebug.h" | 23 | #include "luadebug.h" |
24 | 24 | ||
25 | 25 | ||
26 | |||
26 | static const char *getfuncname (lua_State *L, StkId f, const char **name); | 27 | static const char *getfuncname (lua_State *L, StkId f, const char **name); |
27 | 28 | ||
28 | 29 | ||
29 | static void setnormalized (TObject *d, const TObject *s) { | 30 | static void setnormalized (TObject *d, const TObject *s) { |
30 | switch (s->ttype) { | 31 | if (ttype(s) == LUA_TMARK) { |
31 | case TAG_CMARK: { | 32 | clvalue(d) = infovalue(s)->func; |
32 | clvalue(d) = clvalue(s); | 33 | ttype(d) = LUA_TFUNCTION; |
33 | ttype(d) = TAG_CCLOSURE; | ||
34 | break; | ||
35 | } | ||
36 | case TAG_LMARK: { | ||
37 | clvalue(d) = infovalue(s)->func; | ||
38 | ttype(d) = TAG_LCLOSURE; | ||
39 | break; | ||
40 | } | ||
41 | default: *d = *s; | ||
42 | } | 34 | } |
35 | else *d = *s; | ||
36 | } | ||
37 | |||
38 | |||
39 | static int isLmark (StkId o) { | ||
40 | return (o && ttype(o) == LUA_TMARK && !infovalue(o)->func->isC); | ||
43 | } | 41 | } |
44 | 42 | ||
45 | 43 | ||
@@ -82,9 +80,9 @@ int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
82 | 80 | ||
83 | static int lua_nups (StkId f) { | 81 | static int lua_nups (StkId f) { |
84 | switch (ttype(f)) { | 82 | switch (ttype(f)) { |
85 | case TAG_LCLOSURE: case TAG_CCLOSURE: case TAG_CMARK: | 83 | case LUA_TFUNCTION: |
86 | return clvalue(f)->nupvalues; | 84 | return clvalue(f)->nupvalues; |
87 | case TAG_LMARK: | 85 | case LUA_TMARK: |
88 | return infovalue(f)->func->nupvalues; | 86 | return infovalue(f)->func->nupvalues; |
89 | default: | 87 | default: |
90 | return 0; | 88 | return 0; |
@@ -125,13 +123,13 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
125 | 123 | ||
126 | static int lua_currentpc (StkId f) { | 124 | static int lua_currentpc (StkId f) { |
127 | CallInfo *ci = infovalue(f); | 125 | CallInfo *ci = infovalue(f); |
128 | LUA_ASSERT(ttype(f) == TAG_LMARK, "function has no pc"); | 126 | LUA_ASSERT(isLmark(f), "function has no pc"); |
129 | return (*ci->pc - ci->func->f.l->code) - 1; | 127 | return (*ci->pc - ci->func->f.l->code) - 1; |
130 | } | 128 | } |
131 | 129 | ||
132 | 130 | ||
133 | static int lua_currentline (StkId f) { | 131 | static int lua_currentline (StkId f) { |
134 | if (ttype(f) != TAG_LMARK) | 132 | if (!isLmark(f)) |
135 | return -1; /* only active lua functions have current-line information */ | 133 | return -1; /* only active lua functions have current-line information */ |
136 | else { | 134 | else { |
137 | CallInfo *ci = infovalue(f); | 135 | CallInfo *ci = infovalue(f); |
@@ -143,7 +141,7 @@ static int lua_currentline (StkId f) { | |||
143 | 141 | ||
144 | 142 | ||
145 | static Proto *getluaproto (StkId f) { | 143 | static Proto *getluaproto (StkId f) { |
146 | return (ttype(f) == TAG_LMARK) ? infovalue(f)->func->f.l : NULL; | 144 | return (isLmark(f) ? infovalue(f)->func->f.l : NULL); |
147 | } | 145 | } |
148 | 146 | ||
149 | 147 | ||
@@ -179,22 +177,25 @@ static void infoLproto (lua_Debug *ar, Proto *f) { | |||
179 | } | 177 | } |
180 | 178 | ||
181 | 179 | ||
182 | static void lua_funcinfo (lua_Debug *ar, StkId func) { | 180 | static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) { |
181 | Closure *cl = NULL; | ||
183 | switch (ttype(func)) { | 182 | switch (ttype(func)) { |
184 | case TAG_LCLOSURE: | 183 | case LUA_TFUNCTION: |
185 | infoLproto(ar, clvalue(func)->f.l); | 184 | cl = clvalue(func); |
186 | break; | ||
187 | case TAG_LMARK: | ||
188 | infoLproto(ar, infovalue(func)->func->f.l); | ||
189 | break; | 185 | break; |
190 | case TAG_CCLOSURE: case TAG_CMARK: | 186 | case LUA_TMARK: |
191 | ar->source = "(C)"; | 187 | cl = infovalue(func)->func; |
192 | ar->linedefined = -1; | ||
193 | ar->what = "C"; | ||
194 | break; | 188 | break; |
195 | default: | 189 | default: |
196 | LUA_INTERNALERROR("invalid `func' value"); | 190 | lua_error(L, "value for `lua_getinfo' is not a function"); |
197 | } | 191 | } |
192 | if (cl->isC) { | ||
193 | ar->source = "(C)"; | ||
194 | ar->linedefined = -1; | ||
195 | ar->what = "C"; | ||
196 | } | ||
197 | else | ||
198 | infoLproto(ar, cl->f.l); | ||
198 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); | 199 | luaO_chunkid(ar->short_src, ar->source, sizeof(ar->short_src)); |
199 | if (ar->linedefined == 0) | 200 | if (ar->linedefined == 0) |
200 | ar->what = "main"; | 201 | ar->what = "main"; |
@@ -218,7 +219,7 @@ static const char *travglobals (lua_State *L, const TObject *o) { | |||
218 | int i; | 219 | int i; |
219 | for (i=0; i<g->size; i++) { | 220 | for (i=0; i<g->size; i++) { |
220 | if (luaO_equalObj(o, val(node(g, i))) && | 221 | if (luaO_equalObj(o, val(node(g, i))) && |
221 | ttype(key(node(g, i))) == TAG_STRING) | 222 | ttype(key(node(g, i))) == LUA_TSTRING) |
222 | return tsvalue(key(node(g, i)))->str; | 223 | return tsvalue(key(node(g, i)))->str; |
223 | } | 224 | } |
224 | return NULL; | 225 | return NULL; |
@@ -250,7 +251,7 @@ int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
250 | for (; *what; what++) { | 251 | for (; *what; what++) { |
251 | switch (*what) { | 252 | switch (*what) { |
252 | case 'S': { | 253 | case 'S': { |
253 | lua_funcinfo(ar, func); | 254 | lua_funcinfo(L, ar, func); |
254 | break; | 255 | break; |
255 | } | 256 | } |
256 | case 'l': { | 257 | case 'l': { |
@@ -377,8 +378,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { | |||
377 | 378 | ||
378 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { | 379 | static const char *getobjname (lua_State *L, StkId obj, const char **name) { |
379 | StkId func = aux_stackedfunction(L, 0, obj); | 380 | StkId func = aux_stackedfunction(L, 0, obj); |
380 | if (func == NULL || ttype(func) != TAG_LMARK) | 381 | if (!isLmark(func)) |
381 | return NULL; /* not a Lua function */ | 382 | return NULL; /* not an active Lua function */ |
382 | else { | 383 | else { |
383 | Proto *p = infovalue(func)->func->f.l; | 384 | Proto *p = infovalue(func)->func->f.l; |
384 | int pc = lua_currentpc(func); | 385 | int pc = lua_currentpc(func); |
@@ -409,8 +410,8 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
409 | 410 | ||
410 | static const char *getfuncname (lua_State *L, StkId f, const char **name) { | 411 | static const char *getfuncname (lua_State *L, StkId f, const char **name) { |
411 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ | 412 | StkId func = aux_stackedfunction(L, 0, f); /* calling function */ |
412 | if (func == NULL || ttype(func) != TAG_LMARK) | 413 | if (!isLmark(func)) |
413 | return NULL; /* not a Lua function */ | 414 | return NULL; /* not an active Lua function */ |
414 | else { | 415 | else { |
415 | Proto *p = infovalue(func)->func->f.l; | 416 | Proto *p = infovalue(func)->func->f.l; |
416 | int pc = lua_currentpc(func); | 417 | int pc = lua_currentpc(func); |
@@ -433,7 +434,7 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) { | |||
433 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { | 434 | void luaG_typeerror (lua_State *L, StkId o, const char *op) { |
434 | const char *name; | 435 | const char *name; |
435 | const char *kind = getobjname(L, o, &name); | 436 | const char *kind = getobjname(L, o, &name); |
436 | const char *t = luaO_typename(L, o); | 437 | const char *t = luaO_typename(o); |
437 | if (kind) | 438 | if (kind) |
438 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", | 439 | luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", |
439 | op, kind, name, t); | 440 | op, kind, name, t); |
@@ -442,7 +443,7 @@ void luaG_typeerror (lua_State *L, StkId o, const char *op) { | |||
442 | } | 443 | } |
443 | 444 | ||
444 | 445 | ||
445 | void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op) { | 446 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { |
446 | if (ttype(p1) == t) p1++; | 447 | if (ttype(p1) == t) p1++; |
447 | LUA_ASSERT(ttype(p1) != t, "must be an error"); | 448 | LUA_ASSERT(ttype(p1) != t, "must be an error"); |
448 | luaG_typeerror(L, p1, op); | 449 | luaG_typeerror(L, p1, op); |
@@ -450,8 +451,8 @@ void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op) { | |||
450 | 451 | ||
451 | 452 | ||
452 | void luaG_ordererror (lua_State *L, StkId top) { | 453 | void luaG_ordererror (lua_State *L, StkId top) { |
453 | const char *t1 = luaO_typename(L, top-2); | 454 | const char *t1 = luaO_typename(top-2); |
454 | const char *t2 = luaO_typename(L, top-1); | 455 | const char *t2 = luaO_typename(top-1); |
455 | if (t1[2] == t2[2]) | 456 | if (t1[2] == t2[2]) |
456 | luaO_verror(L, "attempt to compare two %.10s values", t1); | 457 | luaO_verror(L, "attempt to compare two %.10s values", t1); |
457 | else | 458 | else |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.h,v 1.5 2000/08/11 16:17:28 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 1.6 2000/10/02 20:10:55 roberto Exp roberto $ |
3 | ** Auxiliary functions from Debug Interface module | 3 | ** Auxiliary functions from Debug Interface module |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -13,7 +13,7 @@ | |||
13 | 13 | ||
14 | 14 | ||
15 | void luaG_typeerror (lua_State *L, StkId o, const char *op); | 15 | void luaG_typeerror (lua_State *L, StkId o, const char *op); |
16 | void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op); | 16 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op); |
17 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); | 17 | int luaG_getline (int *lineinfo, int pc, int refline, int *refi); |
18 | void luaG_ordererror (lua_State *L, StkId top); | 18 | void luaG_ordererror (lua_State *L, StkId top); |
19 | 19 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.100 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.101 2000/10/04 12:16:08 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -73,7 +73,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
73 | else { | 73 | else { |
74 | luaD_checkstack(L, diff); | 74 | luaD_checkstack(L, diff); |
75 | while (diff--) | 75 | while (diff--) |
76 | ttype(L->top++) = TAG_NIL; | 76 | ttype(L->top++) = LUA_TNIL; |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
@@ -91,7 +91,7 @@ static void luaD_openstack (lua_State *L, StkId pos) { | |||
91 | static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | 91 | static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { |
92 | StkId old_Cbase = L->Cbase; | 92 | StkId old_Cbase = L->Cbase; |
93 | StkId old_top = L->Cbase = L->top; | 93 | StkId old_top = L->Cbase = L->top; |
94 | luaD_checkstack(L, LUA_MINSTACK); /* assures minimum stack size */ | 94 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
95 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 95 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
96 | (*hook)(L, ar); | 96 | (*hook)(L, ar); |
97 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); | 97 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); |
@@ -129,7 +129,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
129 | StkId old_Cbase = L->Cbase; | 129 | StkId old_Cbase = L->Cbase; |
130 | int n; | 130 | int n; |
131 | L->Cbase = base; /* new base for C function */ | 131 | L->Cbase = base; /* new base for C function */ |
132 | luaD_checkstack(L, nup+LUA_MINSTACK); /* assures minimum stack size */ | 132 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
133 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 133 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
134 | *(L->top++) = cl->upvalue[n]; | 134 | *(L->top++) = cl->upvalue[n]; |
135 | if (callhook) | 135 | if (callhook) |
@@ -159,32 +159,26 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { | |||
159 | */ | 159 | */ |
160 | void luaD_call (lua_State *L, StkId func, int nResults) { | 160 | void luaD_call (lua_State *L, StkId func, int nResults) { |
161 | StkId firstResult; | 161 | StkId firstResult; |
162 | retry: /* for `function' tag method */ | 162 | CallInfo ci; |
163 | switch (ttype(func)) { | 163 | Closure *cl; |
164 | case TAG_LCLOSURE: { | 164 | if (ttype(func) != LUA_TFUNCTION) { |
165 | CallInfo ci; | 165 | /* `func' is not a function; check the `function' tag method */ |
166 | ci.func = clvalue(func); | 166 | const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION); |
167 | infovalue(func) = &ci; | 167 | if (ttype(im) == LUA_TNIL) |
168 | ttype(func) = TAG_LMARK; | 168 | luaG_typeerror(L, func, "call"); |
169 | firstResult = luaV_execute(L, ci.func, func+1); | 169 | luaD_openstack(L, func); |
170 | LUA_ASSERT(ttype(func) == TAG_LMARK, "invalid tag"); | 170 | *func = *im; /* tag method is the new function to be called */ |
171 | break; | 171 | LUA_ASSERT(ttype(func) == LUA_TFUNCTION, "invalid tag method"); |
172 | } | ||
173 | case TAG_CCLOSURE: { | ||
174 | ttype(func) = TAG_CMARK; | ||
175 | firstResult = callCclosure(L, clvalue(func), func+1); | ||
176 | LUA_ASSERT(ttype(func) == TAG_CMARK, "invalid tag"); | ||
177 | break; | ||
178 | } | ||
179 | default: { /* `func' is not a function; check the `function' tag method */ | ||
180 | const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION); | ||
181 | if (ttype(im) == TAG_NIL) | ||
182 | luaG_typeerror(L, func, "call"); | ||
183 | luaD_openstack(L, func); | ||
184 | *func = *im; /* tag method is the new function to be called */ | ||
185 | goto retry; /* retry the call */ | ||
186 | } | ||
187 | } | 172 | } |
173 | cl = clvalue(func); | ||
174 | ci.func = cl; | ||
175 | infovalue(func) = &ci; | ||
176 | ttype(func) = LUA_TMARK; | ||
177 | if (cl->isC) | ||
178 | firstResult = callCclosure(L, cl, func+1); | ||
179 | else | ||
180 | firstResult = luaV_execute(L, cl, func+1); | ||
181 | LUA_ASSERT(ttype(func) == LUA_TMARK, "invalid tag"); | ||
188 | /* adjust the number of results */ | 182 | /* adjust the number of results */ |
189 | if (nResults == LUA_MULTRET) | 183 | if (nResults == LUA_MULTRET) |
190 | nResults = L->top - firstResult; | 184 | nResults = L->top - firstResult; |
@@ -250,7 +244,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
250 | old_blocks = L->nblocks; | 244 | old_blocks = L->nblocks; |
251 | status = luaD_runprotected(L, f_parser, &p); | 245 | status = luaD_runprotected(L, f_parser, &p); |
252 | if (status == 0) { | 246 | if (status == 0) { |
253 | /* add new memory to threshould (as it probably will stay) */ | 247 | /* add new memory to threshold (as it probably will stay) */ |
254 | L->GCthreshold += (L->nblocks - old_blocks); | 248 | L->GCthreshold += (L->nblocks - old_blocks); |
255 | } | 249 | } |
256 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | 250 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ |
@@ -331,7 +325,7 @@ struct lua_longjmp { | |||
331 | 325 | ||
332 | static void message (lua_State *L, const char *s) { | 326 | static void message (lua_State *L, const char *s) { |
333 | const TObject *em = luaH_getglobal(L, LUA_ERRORMESSAGE); | 327 | const TObject *em = luaH_getglobal(L, LUA_ERRORMESSAGE); |
334 | if (luaO_type(em) == LUA_TFUNCTION) { | 328 | if (ttype(em) == LUA_TFUNCTION) { |
335 | *L->top = *em; | 329 | *L->top = *em; |
336 | incr_top; | 330 | incr_top; |
337 | lua_pushstring(L, s); | 331 | lua_pushstring(L, s); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.68 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.69 2000/10/02 14:47:43 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,7 +24,7 @@ typedef struct GCState { | |||
24 | 24 | ||
25 | 25 | ||
26 | 26 | ||
27 | static int markobject (GCState *st, TObject *o); | 27 | static void markobject (GCState *st, TObject *o); |
28 | 28 | ||
29 | 29 | ||
30 | /* mark a string; marks larger than 1 cannot be changed */ | 30 | /* mark a string; marks larger than 1 cannot be changed */ |
@@ -73,39 +73,36 @@ static void marktagmethods (lua_State *L, GCState *st) { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static int markobject (GCState *st, TObject *o) { | 76 | static void markclosure (GCState *st, Closure *cl) { |
77 | if (!ismarked(cl)) { | ||
78 | if (!cl->isC) | ||
79 | protomark(cl->f.l); | ||
80 | cl->mark = st->cmark; /* chain it for later traversal */ | ||
81 | st->cmark = cl; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | |||
86 | static void markobject (GCState *st, TObject *o) { | ||
77 | switch (ttype(o)) { | 87 | switch (ttype(o)) { |
78 | case TAG_USERDATA: case TAG_STRING: | 88 | case LUA_TUSERDATA: case LUA_TSTRING: |
79 | strmark(tsvalue(o)); | 89 | strmark(tsvalue(o)); |
80 | break; | 90 | break; |
81 | case TAG_TABLE: { | 91 | case LUA_TMARK: |
92 | markclosure(st, infovalue(o)->func); | ||
93 | break; | ||
94 | case LUA_TFUNCTION: | ||
95 | markclosure(st, clvalue(o)); | ||
96 | break; | ||
97 | case LUA_TTABLE: { | ||
82 | if (!ismarked(hvalue(o))) { | 98 | if (!ismarked(hvalue(o))) { |
83 | hvalue(o)->mark = st->tmark; /* chain it in list of marked */ | 99 | hvalue(o)->mark = st->tmark; /* chain it in list of marked */ |
84 | st->tmark = hvalue(o); | 100 | st->tmark = hvalue(o); |
85 | } | 101 | } |
86 | break; | 102 | break; |
87 | } | 103 | } |
88 | case TAG_LMARK: { | ||
89 | Closure *cl = infovalue(o)->func; | ||
90 | if (!ismarked(cl)) { | ||
91 | protomark(cl->f.l); | ||
92 | cl->mark = st->cmark; /* chain it for later traversal */ | ||
93 | st->cmark = cl; | ||
94 | } | ||
95 | break; | ||
96 | } | ||
97 | case TAG_LCLOSURE: | ||
98 | protomark(clvalue(o)->f.l); | ||
99 | /* go through */ | ||
100 | case TAG_CCLOSURE: case TAG_CMARK: | ||
101 | if (!ismarked(clvalue(o))) { | ||
102 | clvalue(o)->mark = st->cmark; /* chain it for later traversal */ | ||
103 | st->cmark = clvalue(o); | ||
104 | } | ||
105 | break; | ||
106 | default: break; /* numbers, etc */ | 104 | default: break; /* numbers, etc */ |
107 | } | 105 | } |
108 | return 0; | ||
109 | } | 106 | } |
110 | 107 | ||
111 | 108 | ||
@@ -131,8 +128,8 @@ static void markall (lua_State *L) { | |||
131 | st.tmark = h->mark; /* remove it from list */ | 128 | st.tmark = h->mark; /* remove it from list */ |
132 | for (i=0; i<h->size; i++) { | 129 | for (i=0; i<h->size; i++) { |
133 | Node *n = node(h, i); | 130 | Node *n = node(h, i); |
134 | if (ttype(key(n)) != TAG_NIL) { | 131 | if (ttype(key(n)) != LUA_TNIL) { |
135 | if (ttype(val(n)) == TAG_NIL) | 132 | if (ttype(val(n)) == LUA_TNIL) |
136 | luaH_remove(h, key(n)); /* dead element; try to remove it */ | 133 | luaH_remove(h, key(n)); /* dead element; try to remove it */ |
137 | markobject(&st, &n->key); | 134 | markobject(&st, &n->key); |
138 | markobject(&st, &n->val); | 135 | markobject(&st, &n->val); |
@@ -147,11 +144,11 @@ static void markall (lua_State *L) { | |||
147 | static int hasmark (const TObject *o) { | 144 | static int hasmark (const TObject *o) { |
148 | /* valid only for locked objects */ | 145 | /* valid only for locked objects */ |
149 | switch (o->ttype) { | 146 | switch (o->ttype) { |
150 | case TAG_STRING: case TAG_USERDATA: | 147 | case LUA_TSTRING: case LUA_TUSERDATA: |
151 | return tsvalue(o)->marked; | 148 | return tsvalue(o)->marked; |
152 | case TAG_TABLE: | 149 | case LUA_TTABLE: |
153 | return ismarked(hvalue(o)); | 150 | return ismarked(hvalue(o)); |
154 | case TAG_LCLOSURE: case TAG_CCLOSURE: | 151 | case LUA_TFUNCTION: |
155 | return ismarked(clvalue(o)); | 152 | return ismarked(clvalue(o)); |
156 | default: /* number */ | 153 | default: /* number */ |
157 | return 1; | 154 | return 1; |
@@ -271,7 +268,6 @@ static void collectudata (lua_State *L, int all) { | |||
271 | } | 268 | } |
272 | else { /* collect */ | 269 | else { /* collect */ |
273 | int tag = next->u.d.tag; | 270 | int tag = next->u.d.tag; |
274 | if (tag > L->last_tag) tag = TAG_USERDATA; | ||
275 | *p = next->nexthash; | 271 | *p = next->nexthash; |
276 | next->nexthash = L->IMtable[tag].collected; /* chain udata */ | 272 | next->nexthash = L->IMtable[tag].collected; /* chain udata */ |
277 | L->IMtable[tag].collected = next; | 273 | L->IMtable[tag].collected = next; |
@@ -297,7 +293,7 @@ static void checkMbuffer (lua_State *L) { | |||
297 | 293 | ||
298 | static void callgcTM (lua_State *L, const TObject *o) { | 294 | static void callgcTM (lua_State *L, const TObject *o) { |
299 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); | 295 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); |
300 | if (ttype(im) != TAG_NIL) { | 296 | if (ttype(im) != LUA_TNIL) { |
301 | int oldah = L->allowhooks; | 297 | int oldah = L->allowhooks; |
302 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ | 298 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ |
303 | luaD_checkstack(L, 2); | 299 | luaD_checkstack(L, 2); |
@@ -313,7 +309,7 @@ static void callgcTM (lua_State *L, const TObject *o) { | |||
313 | static void callgcTMudata (lua_State *L) { | 309 | static void callgcTMudata (lua_State *L) { |
314 | int tag; | 310 | int tag; |
315 | TObject o; | 311 | TObject o; |
316 | ttype(&o) = TAG_USERDATA; | 312 | ttype(&o) = LUA_TUSERDATA; |
317 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 313 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ |
318 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ | 314 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ |
319 | TString *udata; | 315 | TString *udata; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.50 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.51 2000/10/03 14:03:21 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,14 +18,13 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | 20 | ||
21 | const lua_Type luaO_typearr[] = { /* ORDER LUA_T */ | 21 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; |
22 | LUA_TUSERDATA, LUA_TNUMBER, LUA_TSTRING, LUA_TTABLE, | ||
23 | LUA_TFUNCTION, LUA_TFUNCTION, LUA_TNIL | ||
24 | }; | ||
25 | 22 | ||
26 | 23 | ||
24 | const char *const luaO_typenames[] = { | ||
25 | "userdata", "nil", "number", "string", "table", "function" | ||
26 | }; | ||
27 | 27 | ||
28 | const TObject luaO_nilobject = {TAG_NIL, {NULL}}; | ||
29 | 28 | ||
30 | 29 | ||
31 | /* | 30 | /* |
@@ -41,17 +40,17 @@ lint32 luaO_power2 (lint32 n) { | |||
41 | int luaO_equalObj (const TObject *t1, const TObject *t2) { | 40 | int luaO_equalObj (const TObject *t1, const TObject *t2) { |
42 | if (ttype(t1) != ttype(t2)) return 0; | 41 | if (ttype(t1) != ttype(t2)) return 0; |
43 | switch (ttype(t1)) { | 42 | switch (ttype(t1)) { |
44 | case TAG_NUMBER: | 43 | case LUA_TNUMBER: |
45 | return nvalue(t1) == nvalue(t2); | 44 | return nvalue(t1) == nvalue(t2); |
46 | case TAG_STRING: case TAG_USERDATA: | 45 | case LUA_TSTRING: case LUA_TUSERDATA: |
47 | return tsvalue(t1) == tsvalue(t2); | 46 | return tsvalue(t1) == tsvalue(t2); |
48 | case TAG_TABLE: | 47 | case LUA_TTABLE: |
49 | return hvalue(t1) == hvalue(t2); | 48 | return hvalue(t1) == hvalue(t2); |
50 | case TAG_CCLOSURE: case TAG_LCLOSURE: | 49 | case LUA_TFUNCTION: |
51 | return clvalue(t1) == clvalue(t2); | 50 | return clvalue(t1) == clvalue(t2); |
52 | default: | 51 | default: |
53 | LUA_ASSERT(ttype(t1) == TAG_NIL, "invalid type"); | 52 | LUA_ASSERT(ttype(t1) == LUA_TNIL, "invalid type"); |
54 | return 1; /* TAG_NIL */ | 53 | return 1; /* LUA_TNIL */ |
55 | } | 54 | } |
56 | } | 55 | } |
57 | 56 | ||
@@ -80,7 +79,7 @@ int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */ | |||
80 | /* this function needs to handle only '%d' and '%.XXs' formats */ | 79 | /* this function needs to handle only '%d' and '%.XXs' formats */ |
81 | void luaO_verror (lua_State *L, const char *fmt, ...) { | 80 | void luaO_verror (lua_State *L, const char *fmt, ...) { |
82 | va_list argp; | 81 | va_list argp; |
83 | char buff[600]; /* to hold formated message */ | 82 | char buff[600]; /* to hold formatted message */ |
84 | va_start(argp, fmt); | 83 | va_start(argp, fmt); |
85 | vsprintf(buff, fmt, argp); | 84 | vsprintf(buff, fmt, argp); |
86 | va_end(argp); | 85 | va_end(argp); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.77 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.78 2000/10/02 20:10:55 roberto Exp roberto $ |
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 | */ |
@@ -31,41 +31,24 @@ | |||
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | 33 | ||
34 | /* | 34 | /* mark for closures active in the stack */ |
35 | ** Lua TYPES | 35 | #define LUA_TMARK 6 |
36 | ** WARNING: if you change the order of this enumeration, | ||
37 | ** grep "ORDER LUA_T" | ||
38 | */ | ||
39 | typedef enum { | ||
40 | TAG_USERDATA = 0, /* default tag for userdata */ | ||
41 | TAG_NUMBER, /* fixed tag for numbers */ | ||
42 | TAG_STRING, /* fixed tag for strings */ | ||
43 | TAG_TABLE, /* default tag for tables */ | ||
44 | TAG_LCLOSURE, /* fixed tag for Lua closures */ | ||
45 | TAG_CCLOSURE, /* fixed tag for C closures */ | ||
46 | TAG_NIL, /* last "pre-defined" tag */ | ||
47 | |||
48 | TAG_LMARK, /* mark for Lua closures */ | ||
49 | TAG_CMARK /* mark for C closures */ | ||
50 | 36 | ||
51 | } lua_Tag; | ||
52 | 37 | ||
53 | /* tags for values visible from Lua == first user-created tag */ | 38 | /* tags for values visible from Lua == first user-created tag */ |
54 | #define NUM_TAGS 7 | 39 | #define NUM_TAGS 6 |
55 | 40 | ||
56 | 41 | ||
57 | /* | 42 | /* check whether `t' is a mark */ |
58 | ** check whether `t' is a mark | 43 | #define is_T_MARK(t) ((t) == LUA_TMARK) |
59 | */ | ||
60 | #define is_T_MARK(t) ((t) == TAG_LMARK || (t) == TAG_CMARK) | ||
61 | 44 | ||
62 | 45 | ||
63 | typedef union { | 46 | typedef union { |
64 | struct TString *ts; /* TAG_STRING, TAG_USERDATA */ | 47 | struct TString *ts; /* LUA_TSTRING, LUA_TUSERDATA */ |
65 | struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_CMARK */ | 48 | struct Closure *cl; /* LUA_TFUNCTION */ |
66 | struct Hash *a; /* TAG_TABLE */ | 49 | struct Hash *a; /* LUA_TTABLE */ |
67 | struct CallInfo *i; /* TAG_LMARK */ | 50 | struct CallInfo *i; /* LUA_TLMARK */ |
68 | Number n; /* TAG_NUMBER */ | 51 | Number n; /* LUA_TNUMBER */ |
69 | } Value; | 52 | } Value; |
70 | 53 | ||
71 | 54 | ||
@@ -80,7 +63,7 @@ typedef union { | |||
80 | 63 | ||
81 | 64 | ||
82 | typedef struct lua_TObject { | 65 | typedef struct lua_TObject { |
83 | lua_Tag ttype; | 66 | int ttype; |
84 | Value value; | 67 | Value value; |
85 | } TObject; | 68 | } TObject; |
86 | 69 | ||
@@ -150,11 +133,15 @@ typedef struct Closure { | |||
150 | } f; | 133 | } f; |
151 | struct Closure *next; | 134 | struct Closure *next; |
152 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 135 | struct Closure *mark; /* marked closures (point to itself when not marked) */ |
153 | int nupvalues; | 136 | short isC; /* 0 for Lua functions, 1 for C functions */ |
137 | short nupvalues; | ||
154 | TObject upvalue[1]; | 138 | TObject upvalue[1]; |
155 | } Closure; | 139 | } Closure; |
156 | 140 | ||
157 | 141 | ||
142 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC) | ||
143 | |||
144 | |||
158 | typedef struct Node { | 145 | typedef struct Node { |
159 | TObject key; | 146 | TObject key; |
160 | TObject val; | 147 | TObject val; |
@@ -189,12 +176,12 @@ typedef struct CallInfo { | |||
189 | } CallInfo; | 176 | } CallInfo; |
190 | 177 | ||
191 | 178 | ||
192 | extern const lua_Type luaO_typearr[]; | ||
193 | extern const TObject luaO_nilobject; | 179 | extern const TObject luaO_nilobject; |
180 | extern const char *const luaO_typenames[]; | ||
181 | |||
182 | |||
183 | #define luaO_typename(o) (luaO_typenames[ttype(o)]) | ||
194 | 184 | ||
195 | #define luaO_tag2type(t) (luaO_typearr[(int)(t)]) | ||
196 | #define luaO_type(o) (luaO_tag2type(ttype(o))) | ||
197 | #define luaO_typename(L, o) (lua_typename(L, luaO_type(o))) | ||
198 | 185 | ||
199 | lint32 luaO_power2 (lint32 n); | 186 | lint32 luaO_power2 (lint32 n); |
200 | char *luaO_openspace (lua_State *L, size_t n); | 187 | char *luaO_openspace (lua_State *L, size_t n); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.52 2000/09/11 17:38:42 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.53 2000/09/14 14:09:31 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -525,7 +525,7 @@ static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) { | |||
525 | luaL_putchar(b, '"'); | 525 | luaL_putchar(b, '"'); |
526 | } | 526 | } |
527 | 527 | ||
528 | /* maximum size of each formated item (> len(format('%99.99f', -1e308))) */ | 528 | /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ |
529 | #define MAX_ITEM 512 | 529 | #define MAX_ITEM 512 |
530 | /* maximum size of each format specification (such as '%-099.99d') */ | 530 | /* maximum size of each format specification (such as '%-099.99d') */ |
531 | #define MAX_FORMAT 20 | 531 | #define MAX_FORMAT 20 |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.55 2000/09/11 20:29:27 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.56 2000/09/29 12:42:13 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | #define TagDefault TAG_TABLE | 34 | #define TagDefault LUA_TTABLE |
35 | 35 | ||
36 | 36 | ||
37 | 37 | ||
@@ -42,19 +42,19 @@ | |||
42 | Node *luaH_mainposition (const Hash *t, const TObject *key) { | 42 | Node *luaH_mainposition (const Hash *t, const TObject *key) { |
43 | unsigned long h; | 43 | unsigned long h; |
44 | switch (ttype(key)) { | 44 | switch (ttype(key)) { |
45 | case TAG_NUMBER: | 45 | case LUA_TNUMBER: |
46 | h = (unsigned long)(long)nvalue(key); | 46 | h = (unsigned long)(long)nvalue(key); |
47 | break; | 47 | break; |
48 | case TAG_STRING: | 48 | case LUA_TSTRING: |
49 | h = tsvalue(key)->u.s.hash; | 49 | h = tsvalue(key)->u.s.hash; |
50 | break; | 50 | break; |
51 | case TAG_USERDATA: | 51 | case LUA_TUSERDATA: |
52 | h = IntPoint(tsvalue(key)); | 52 | h = IntPoint(tsvalue(key)); |
53 | break; | 53 | break; |
54 | case TAG_TABLE: | 54 | case LUA_TTABLE: |
55 | h = IntPoint(hvalue(key)); | 55 | h = IntPoint(hvalue(key)); |
56 | break; | 56 | break; |
57 | case TAG_LCLOSURE: case TAG_CCLOSURE: | 57 | case LUA_TFUNCTION: |
58 | h = IntPoint(clvalue(key)); | 58 | h = IntPoint(clvalue(key)); |
59 | break; | 59 | break; |
60 | default: | 60 | default: |
@@ -84,7 +84,7 @@ static const TObject *luaH_getany (lua_State *L, const Hash *t, | |||
84 | const TObject *luaH_getnum (const Hash *t, Number key) { | 84 | const TObject *luaH_getnum (const Hash *t, Number key) { |
85 | Node *n = &t->node[(unsigned long)(long)key&(t->size-1)]; | 85 | Node *n = &t->node[(unsigned long)(long)key&(t->size-1)]; |
86 | do { | 86 | do { |
87 | if (ttype(&n->key) == TAG_NUMBER && nvalue(&n->key) == key) | 87 | if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key) |
88 | return &n->val; | 88 | return &n->val; |
89 | n = n->next; | 89 | n = n->next; |
90 | } while (n); | 90 | } while (n); |
@@ -96,7 +96,7 @@ const TObject *luaH_getnum (const Hash *t, Number key) { | |||
96 | const TObject *luaH_getstr (const Hash *t, TString *key) { | 96 | const TObject *luaH_getstr (const Hash *t, TString *key) { |
97 | Node *n = &t->node[key->u.s.hash&(t->size-1)]; | 97 | Node *n = &t->node[key->u.s.hash&(t->size-1)]; |
98 | do { | 98 | do { |
99 | if (ttype(&n->key) == TAG_STRING && tsvalue(&n->key) == key) | 99 | if (ttype(&n->key) == LUA_TSTRING && tsvalue(&n->key) == key) |
100 | return &n->val; | 100 | return &n->val; |
101 | n = n->next; | 101 | n = n->next; |
102 | } while (n); | 102 | } while (n); |
@@ -106,8 +106,8 @@ const TObject *luaH_getstr (const Hash *t, TString *key) { | |||
106 | 106 | ||
107 | const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) { | 107 | const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) { |
108 | switch (ttype(key)) { | 108 | switch (ttype(key)) { |
109 | case TAG_NUMBER: return luaH_getnum(t, nvalue(key)); | 109 | case LUA_TNUMBER: return luaH_getnum(t, nvalue(key)); |
110 | case TAG_STRING: return luaH_getstr(t, tsvalue(key)); | 110 | case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); |
111 | default: return luaH_getany(L, t, key); | 111 | default: return luaH_getany(L, t, key); |
112 | } | 112 | } |
113 | } | 113 | } |
@@ -115,7 +115,7 @@ const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key) { | |||
115 | 115 | ||
116 | Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { | 116 | Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { |
117 | int i; | 117 | int i; |
118 | if (ttype(key) == TAG_NIL) | 118 | if (ttype(key) == LUA_TNIL) |
119 | i = 0; /* first iteration */ | 119 | i = 0; /* first iteration */ |
120 | else { | 120 | else { |
121 | const TObject *v = luaH_get(L, t, key); | 121 | const TObject *v = luaH_get(L, t, key); |
@@ -126,7 +126,7 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { | |||
126 | } | 126 | } |
127 | for (; i<t->size; i++) { | 127 | for (; i<t->size; i++) { |
128 | Node *n = node(t, i); | 128 | Node *n = node(t, i); |
129 | if (ttype(val(n)) != TAG_NIL) | 129 | if (ttype(val(n)) != LUA_TNIL) |
130 | return n; | 130 | return n; |
131 | } | 131 | } |
132 | return NULL; /* no more elements */ | 132 | return NULL; /* no more elements */ |
@@ -138,8 +138,8 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { | |||
138 | ** hash, change `key' for a number with the same hash. | 138 | ** hash, change `key' for a number with the same hash. |
139 | */ | 139 | */ |
140 | void luaH_remove (Hash *t, TObject *key) { | 140 | void luaH_remove (Hash *t, TObject *key) { |
141 | if (ttype(key) == TAG_NUMBER || | 141 | if (ttype(key) == LUA_TNUMBER || |
142 | (ttype(key) == TAG_STRING && tsvalue(key)->u.s.len <= 30)) | 142 | (ttype(key) == LUA_TSTRING && tsvalue(key)->u.s.len <= 30)) |
143 | return; /* do not remove numbers nor small strings */ | 143 | return; /* do not remove numbers nor small strings */ |
144 | else { | 144 | else { |
145 | /* try to find a number `n' with the same hash as `key' */ | 145 | /* try to find a number `n' with the same hash as `key' */ |
@@ -151,7 +151,7 @@ void luaH_remove (Hash *t, TObject *key) { | |||
151 | return; /* give up; (to avoid overflow) */ | 151 | return; /* give up; (to avoid overflow) */ |
152 | n += t->size; | 152 | n += t->size; |
153 | } | 153 | } |
154 | ttype(key) = TAG_NUMBER; | 154 | ttype(key) = LUA_TNUMBER; |
155 | nvalue(key) = n; | 155 | nvalue(key) = n; |
156 | LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); | 156 | LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); |
157 | } | 157 | } |
@@ -164,7 +164,7 @@ static void setnodevector (lua_State *L, Hash *t, lint32 size) { | |||
164 | lua_error(L, "table overflow"); | 164 | lua_error(L, "table overflow"); |
165 | t->node = luaM_newvector(L, size, Node); | 165 | t->node = luaM_newvector(L, size, Node); |
166 | for (i=0; i<(int)size; i++) { | 166 | for (i=0; i<(int)size; i++) { |
167 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL; | 167 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; |
168 | t->node[i].next = NULL; | 168 | t->node[i].next = NULL; |
169 | } | 169 | } |
170 | L->nblocks += gcsize(L, size) - gcsize(L, t->size); | 170 | L->nblocks += gcsize(L, size) - gcsize(L, t->size); |
@@ -200,7 +200,7 @@ static int numuse (const Hash *t) { | |||
200 | int realuse = 0; | 200 | int realuse = 0; |
201 | int i; | 201 | int i; |
202 | for (i=0; i<size; i++) { | 202 | for (i=0; i<size; i++) { |
203 | if (ttype(&v[i].val) != TAG_NIL) | 203 | if (ttype(&v[i].val) != LUA_TNIL) |
204 | realuse++; | 204 | realuse++; |
205 | } | 205 | } |
206 | return realuse; | 206 | return realuse; |
@@ -222,7 +222,7 @@ static void rehash (lua_State *L, Hash *t) { | |||
222 | setnodevector(L, t, oldsize); | 222 | setnodevector(L, t, oldsize); |
223 | for (i=0; i<oldsize; i++) { | 223 | for (i=0; i<oldsize; i++) { |
224 | Node *old = nold+i; | 224 | Node *old = nold+i; |
225 | if (ttype(&old->val) != TAG_NIL) | 225 | if (ttype(&old->val) != LUA_TNIL) |
226 | *luaH_set(L, t, &old->key) = old->val; | 226 | *luaH_set(L, t, &old->key) = old->val; |
227 | } | 227 | } |
228 | luaM_free(L, nold); /* free old array */ | 228 | luaM_free(L, nold); /* free old array */ |
@@ -248,7 +248,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) { | |||
248 | else n = n->next; | 248 | else n = n->next; |
249 | } while (n); | 249 | } while (n); |
250 | /* `key' not found; must insert it */ | 250 | /* `key' not found; must insert it */ |
251 | if (ttype(&mp->key) != TAG_NIL) { /* main position is not free? */ | 251 | if (ttype(&mp->key) != LUA_TNIL) { /* main position is not free? */ |
252 | Node *othern; /* main position of colliding node */ | 252 | Node *othern; /* main position of colliding node */ |
253 | n = t->firstfree; /* get a free place */ | 253 | n = t->firstfree; /* get a free place */ |
254 | /* is colliding node out of its main position? (can only happens if | 254 | /* is colliding node out of its main position? (can only happens if |
@@ -269,7 +269,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) { | |||
269 | } | 269 | } |
270 | mp->key = *key; | 270 | mp->key = *key; |
271 | for (;;) { /* correct `firstfree' */ | 271 | for (;;) { /* correct `firstfree' */ |
272 | if (ttype(&t->firstfree->key) == TAG_NIL) | 272 | if (ttype(&t->firstfree->key) == LUA_TNIL) |
273 | return &mp->val; /* OK; table still has a free place */ | 273 | return &mp->val; /* OK; table still has a free place */ |
274 | else if (t->firstfree == t->node) break; /* cannot decrement from here */ | 274 | else if (t->firstfree == t->node) break; /* cannot decrement from here */ |
275 | else (t->firstfree)--; | 275 | else (t->firstfree)--; |
@@ -281,7 +281,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) { | |||
281 | 281 | ||
282 | TObject *luaH_setint (lua_State *L, Hash *t, int key) { | 282 | TObject *luaH_setint (lua_State *L, Hash *t, int key) { |
283 | TObject index; | 283 | TObject index; |
284 | ttype(&index) = TAG_NUMBER; | 284 | ttype(&index) = LUA_TNUMBER; |
285 | nvalue(&index) = key; | 285 | nvalue(&index) = key; |
286 | return luaH_set(L, t, &index); | 286 | return luaH_set(L, t, &index); |
287 | } | 287 | } |
@@ -289,10 +289,10 @@ TObject *luaH_setint (lua_State *L, Hash *t, int key) { | |||
289 | 289 | ||
290 | void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) { | 290 | void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) { |
291 | TObject *value, index; | 291 | TObject *value, index; |
292 | ttype(&index) = TAG_STRING; | 292 | ttype(&index) = LUA_TSTRING; |
293 | tsvalue(&index) = key; | 293 | tsvalue(&index) = key; |
294 | value = luaH_set(L, t, &index); | 294 | value = luaH_set(L, t, &index); |
295 | ttype(value) = TAG_NUMBER; | 295 | ttype(value) = LUA_TNUMBER; |
296 | nvalue(value) = val; | 296 | nvalue(value) = val; |
297 | } | 297 | } |
298 | 298 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.46 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.47 2000/10/02 20:10:55 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 | */ |
@@ -93,7 +93,8 @@ static int listcode (lua_State *L) { | |||
93 | int pc; | 93 | int pc; |
94 | Proto *p; | 94 | Proto *p; |
95 | int res; | 95 | int res; |
96 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); | 96 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
97 | 1, "Lua function expected"); | ||
97 | p = clvalue(luaA_index(L, 1))->f.l; | 98 | p = clvalue(luaA_index(L, 1))->f.l; |
98 | lua_newtable(L); | 99 | lua_newtable(L); |
99 | setnameval(L, "maxstack", p->maxstacksize); | 100 | setnameval(L, "maxstack", p->maxstacksize); |
@@ -111,7 +112,8 @@ static int listcode (lua_State *L) { | |||
111 | static int liststrings (lua_State *L) { | 112 | static int liststrings (lua_State *L) { |
112 | Proto *p; | 113 | Proto *p; |
113 | int i; | 114 | int i; |
114 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); | 115 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
116 | 1, "Lua function expected"); | ||
115 | p = clvalue(luaA_index(L, 1))->f.l; | 117 | p = clvalue(luaA_index(L, 1))->f.l; |
116 | lua_newtable(L); | 118 | lua_newtable(L); |
117 | for (i=0; i<p->nkstr; i++) { | 119 | for (i=0; i<p->nkstr; i++) { |
@@ -128,7 +130,8 @@ static int listlocals (lua_State *L) { | |||
128 | int pc = luaL_check_int(L, 2) - 1; | 130 | int pc = luaL_check_int(L, 2) - 1; |
129 | int i = 0; | 131 | int i = 0; |
130 | const char *name; | 132 | const char *name; |
131 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); | 133 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
134 | 1, "Lua function expected"); | ||
132 | p = clvalue(luaA_index(L, 1))->f.l; | 135 | p = clvalue(luaA_index(L, 1))->f.l; |
133 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 136 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
134 | lua_pushstring(L, name); | 137 | lua_pushstring(L, name); |
@@ -177,7 +180,7 @@ static int mem_query (lua_State *L) { | |||
177 | 180 | ||
178 | static int hash_query (lua_State *L) { | 181 | static int hash_query (lua_State *L) { |
179 | if (lua_isnull(L, 2)) { | 182 | if (lua_isnull(L, 2)) { |
180 | luaL_arg_check(L, lua_tag(L, 1) == TAG_STRING, 1, "string expected"); | 183 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, "string expected"); |
181 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); | 184 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); |
182 | } | 185 | } |
183 | else { | 186 | else { |
@@ -226,7 +229,7 @@ static int string_query (lua_State *L) { | |||
226 | TString *ts; | 229 | TString *ts; |
227 | int n = 0; | 230 | int n = 0; |
228 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { | 231 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { |
229 | ttype(L->top) = TAG_STRING; | 232 | ttype(L->top) = LUA_TSTRING; |
230 | tsvalue(L->top) = ts; | 233 | tsvalue(L->top) = ts; |
231 | incr_top; | 234 | incr_top; |
232 | n++; | 235 | n++; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.51 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.52 2000/10/03 14:27:44 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -38,7 +38,7 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) { | |||
38 | int e = findevent(name); | 38 | int e = findevent(name); |
39 | if (e >= IM_N) | 39 | if (e >= IM_N) |
40 | luaO_verror(L, "event `%.50s' is deprecated", name); | 40 | luaO_verror(L, "event `%.50s' is deprecated", name); |
41 | if (e == IM_GC && t == TAG_TABLE) | 41 | if (e == IM_GC && t == LUA_TTABLE) |
42 | luaO_verror(L, "event `gc' for tables is deprecated"); | 42 | luaO_verror(L, "event `gc' for tables is deprecated"); |
43 | if (e < 0) | 43 | if (e < 0) |
44 | luaO_verror(L, "`%.50s' is not a valid event name", name); | 44 | luaO_verror(L, "`%.50s' is not a valid event name", name); |
@@ -47,29 +47,28 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) { | |||
47 | 47 | ||
48 | 48 | ||
49 | 49 | ||
50 | /* events in TAG_NIL are all allowed, since this is used as a | 50 | /* events in LUA_TNIL are all allowed, since this is used as a |
51 | * 'placeholder' for "default" fallbacks | 51 | * 'placeholder' for "default" fallbacks |
52 | */ | 52 | */ |
53 | /* ORDER LUA_T, ORDER IM */ | 53 | /* ORDER LUA_T, ORDER IM */ |
54 | static const char luaT_validevents[NUM_TAGS][IM_N] = { | 54 | static const char luaT_validevents[NUM_TAGS][IM_N] = { |
55 | {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */ | 55 | {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TUSERDATA */ |
56 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */ | 56 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_TNIL */ |
57 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */ | 57 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_TNUMBER */ |
58 | {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_TABLE */ | 58 | {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_TSTRING */ |
59 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LCLOSURE */ | 59 | {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TTABLE */ |
60 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CCLOSURE */ | 60 | {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0} /* LUA_TFUNCTION */ |
61 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */ | ||
62 | }; | 61 | }; |
63 | 62 | ||
64 | int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | 63 | int luaT_validevent (int t, int e) { /* ORDER LUA_T */ |
65 | return (t > TAG_NIL) ? 1 : luaT_validevents[t][e]; | 64 | return (t >= NUM_TAGS) ? 1 : luaT_validevents[t][e]; |
66 | } | 65 | } |
67 | 66 | ||
68 | 67 | ||
69 | static void init_entry (lua_State *L, int tag) { | 68 | static void init_entry (lua_State *L, int tag) { |
70 | int i; | 69 | int i; |
71 | for (i=0; i<IM_N; i++) | 70 | for (i=0; i<IM_N; i++) |
72 | ttype(luaT_getim(L, tag, i)) = TAG_NIL; | 71 | ttype(luaT_getim(L, tag, i)) = LUA_TNIL; |
73 | L->IMtable[tag].collected = NULL; | 72 | L->IMtable[tag].collected = NULL; |
74 | } | 73 | } |
75 | 74 | ||
@@ -100,7 +99,7 @@ static void checktag (lua_State *L, int tag) { | |||
100 | } | 99 | } |
101 | 100 | ||
102 | void luaT_realtag (lua_State *L, int tag) { | 101 | void luaT_realtag (lua_State *L, int tag) { |
103 | if (!(NUM_TAGS <= tag && tag <= L->last_tag)) | 102 | if (!validtag(tag)) |
104 | luaO_verror(L, "tag %d was not created by `newtag'", tag); | 103 | luaO_verror(L, "tag %d was not created by `newtag'", tag); |
105 | } | 104 | } |
106 | 105 | ||
@@ -117,20 +116,12 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { | |||
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
120 | const TObject *luaT_gettagmethods (lua_State *L, const TObject *o) { | 119 | int luaT_tag (const TObject *o) { |
121 | lua_Tag t = ttype(o); | 120 | int t = ttype(o); |
122 | switch (t) { | 121 | switch (t) { |
123 | case TAG_USERDATA: { | 122 | case LUA_TUSERDATA: return tsvalue(o)->u.d.tag; |
124 | int tag = tsvalue(o)->u.d.tag; | 123 | case LUA_TTABLE: return hvalue(o)->htag; |
125 | if (tag > L->last_tag) | 124 | default: return t; |
126 | return L->IMtable[TAG_USERDATA].int_method; | ||
127 | else | ||
128 | return L->IMtable[tag].int_method; | ||
129 | } | ||
130 | case TAG_TABLE: | ||
131 | return L->IMtable[hvalue(o)->htag].int_method; | ||
132 | default: | ||
133 | return L->IMtable[(int)t].int_method;; | ||
134 | } | 125 | } |
135 | } | 126 | } |
136 | 127 | ||
@@ -142,7 +133,7 @@ void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
142 | if (luaT_validevent(t, e)) | 133 | if (luaT_validevent(t, e)) |
143 | *L->top = *luaT_getim(L, t,e); | 134 | *L->top = *luaT_getim(L, t,e); |
144 | else | 135 | else |
145 | ttype(L->top) = TAG_NIL; | 136 | ttype(L->top) = LUA_TNIL; |
146 | incr_top; | 137 | incr_top; |
147 | } | 138 | } |
148 | 139 | ||
@@ -156,8 +147,8 @@ void lua_settagmethod (lua_State *L, int t, const char *event) { | |||
156 | checktag(L, t); | 147 | checktag(L, t); |
157 | if (!luaT_validevent(t, e)) | 148 | if (!luaT_validevent(t, e)) |
158 | luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", | 149 | luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", |
159 | luaT_eventname[e], lua_typename(L, luaO_tag2type(t)), | 150 | luaT_eventname[e], luaO_typenames[t], |
160 | (t == TAG_TABLE || t == TAG_USERDATA) ? " with default tag" | 151 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? " with default tag" |
161 | : ""); | 152 | : ""); |
162 | temp = *(L->top - 1); | 153 | temp = *(L->top - 1); |
163 | *(L->top - 1) = *luaT_getim(L, t,e); | 154 | *(L->top - 1) = *luaT_getim(L, t,e); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 1.15 2000/09/05 19:33:32 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.16 2000/10/03 14:27:44 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,14 +42,17 @@ struct IM { | |||
42 | 42 | ||
43 | 43 | ||
44 | #define luaT_getim(L,tag,event) (&L->IMtable[tag].int_method[event]) | 44 | #define luaT_getim(L,tag,event) (&L->IMtable[tag].int_method[event]) |
45 | #define luaT_getimbyObj(L,o,e) (&luaT_gettagmethods((L),(o))[e]) | 45 | #define luaT_getimbyObj(L,o,e) (luaT_getim((L),luaT_tag(o),(e))) |
46 | |||
47 | |||
48 | #define validtag(t) (NUM_TAGS <= (t) && (t) <= L->last_tag) | ||
46 | 49 | ||
47 | extern const char *const luaT_eventname[]; | 50 | extern const char *const luaT_eventname[]; |
48 | 51 | ||
49 | 52 | ||
50 | void luaT_init (lua_State *L); | 53 | void luaT_init (lua_State *L); |
51 | void luaT_realtag (lua_State *L, int tag); | 54 | void luaT_realtag (lua_State *L, int tag); |
52 | const TObject *luaT_gettagmethods (lua_State *L, const TObject *o); | 55 | int luaT_tag (const TObject *o); |
53 | int luaT_validevent (int t, int e); /* used by compatibility module */ | 56 | int luaT_validevent (int t, int e); /* used by compatibility module */ |
54 | 57 | ||
55 | 58 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.71 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.72 2000/10/02 20:10:55 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
@@ -47,11 +47,17 @@ typedef struct lua_State lua_State; | |||
47 | 47 | ||
48 | typedef int (*lua_CFunction) (lua_State *L); | 48 | typedef int (*lua_CFunction) (lua_State *L); |
49 | 49 | ||
50 | /* | ||
51 | ** types returned by `lua_type' | ||
52 | */ | ||
53 | #define LUA_TNONE (-1) | ||
50 | 54 | ||
51 | typedef enum lua_Type { | 55 | #define LUA_TUSERDATA 0 |
52 | LUA_NOVALUE, LUA_TUSERDATA, LUA_TNUMBER, LUA_TSTRING, | 56 | #define LUA_TNIL 1 |
53 | LUA_TTABLE, LUA_TFUNCTION, LUA_TNIL | 57 | #define LUA_TNUMBER 2 |
54 | } lua_Type; | 58 | #define LUA_TSTRING 3 |
59 | #define LUA_TTABLE 4 | ||
60 | #define LUA_TFUNCTION 5 | ||
55 | 61 | ||
56 | 62 | ||
57 | 63 | ||
@@ -77,8 +83,8 @@ int lua_stackspace (lua_State *L); | |||
77 | ** access functions (stack -> C) | 83 | ** access functions (stack -> C) |
78 | */ | 84 | */ |
79 | 85 | ||
80 | lua_Type lua_type (lua_State *L, int index); | 86 | int lua_type (lua_State *L, int index); |
81 | const char *lua_typename (lua_State *L, lua_Type t); | 87 | const char *lua_typename (lua_State *L, int t); |
82 | int lua_isnumber (lua_State *L, int index); | 88 | int lua_isnumber (lua_State *L, int index); |
83 | int lua_isstring (lua_State *L, int index); | 89 | int lua_isstring (lua_State *L, int index); |
84 | int lua_iscfunction (lua_State *L, int index); | 90 | int lua_iscfunction (lua_State *L, int index); |
@@ -184,7 +190,7 @@ void lua_concat (lua_State *L, int n); | |||
184 | #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) | 190 | #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) |
185 | #define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA) | 191 | #define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA) |
186 | #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) | 192 | #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) |
187 | #define lua_isnull(L,n) (lua_type(L,n) == LUA_NOVALUE) | 193 | #define lua_isnull(L,n) (lua_type(L,n) == LUA_TNONE) |
188 | 194 | ||
189 | #endif | 195 | #endif |
190 | 196 | ||
@@ -224,3 +230,4 @@ void lua_concat (lua_State *L, int n); | |||
224 | * | 230 | * |
225 | * This implementation contains no third-party code. | 231 | * This implementation contains no third-party code. |
226 | ******************************************************************************/ | 232 | ******************************************************************************/ |
233 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.141 2000/10/03 14:27:44 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.142 2000/10/04 12:16:08 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,25 +40,25 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | int luaV_tonumber (TObject *obj) { | 42 | int luaV_tonumber (TObject *obj) { |
43 | if (ttype(obj) != TAG_STRING) | 43 | if (ttype(obj) != LUA_TSTRING) |
44 | return 1; | 44 | return 1; |
45 | else { | 45 | else { |
46 | if (!luaO_str2d(svalue(obj), &nvalue(obj))) | 46 | if (!luaO_str2d(svalue(obj), &nvalue(obj))) |
47 | return 2; | 47 | return 2; |
48 | ttype(obj) = TAG_NUMBER; | 48 | ttype(obj) = LUA_TNUMBER; |
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ | 54 | int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ |
55 | if (ttype(obj) != TAG_NUMBER) | 55 | if (ttype(obj) != LUA_TNUMBER) |
56 | return 1; | 56 | return 1; |
57 | else { | 57 | else { |
58 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 58 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
59 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 59 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
60 | tsvalue(obj) = luaS_new(L, s); | 60 | tsvalue(obj) = luaS_new(L, s); |
61 | ttype(obj) = TAG_STRING; | 61 | ttype(obj) = LUA_TSTRING; |
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | } | 64 | } |
@@ -85,27 +85,29 @@ static void traceexec (lua_State *L, StkId base, StkId top, lua_Hook linehook) { | |||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static Closure *luaV_closure (lua_State *L, lua_Tag t, int nelems) { | 88 | static Closure *luaV_closure (lua_State *L, int nelems) { |
89 | Closure *c = luaF_newclosure(L, nelems); | 89 | Closure *c = luaF_newclosure(L, nelems); |
90 | L->top -= nelems; | 90 | L->top -= nelems; |
91 | while (nelems--) | 91 | while (nelems--) |
92 | c->upvalue[nelems] = *(L->top+nelems); | 92 | c->upvalue[nelems] = *(L->top+nelems); |
93 | ttype(L->top) = t; | ||
94 | clvalue(L->top) = c; | 93 | clvalue(L->top) = c; |
94 | ttype(L->top) = LUA_TFUNCTION; | ||
95 | incr_top; | 95 | incr_top; |
96 | return c; | 96 | return c; |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void luaV_Cclosure (lua_State *L, lua_CFunction c, int nelems) { | 100 | void luaV_Cclosure (lua_State *L, lua_CFunction c, int nelems) { |
101 | Closure *cl = luaV_closure(L, TAG_CCLOSURE, nelems); | 101 | Closure *cl = luaV_closure(L, nelems); |
102 | cl->f.c = c; | 102 | cl->f.c = c; |
103 | cl->isC = 1; | ||
103 | } | 104 | } |
104 | 105 | ||
105 | 106 | ||
106 | void luaV_Lclosure (lua_State *L, Proto *l, int nelems) { | 107 | void luaV_Lclosure (lua_State *L, Proto *l, int nelems) { |
107 | Closure *cl = luaV_closure(L, TAG_LCLOSURE, nelems); | 108 | Closure *cl = luaV_closure(L, nelems); |
108 | cl->f.l = l; | 109 | cl->f.l = l; |
110 | cl->isC = 0; | ||
109 | } | 111 | } |
110 | 112 | ||
111 | 113 | ||
@@ -116,21 +118,21 @@ void luaV_Lclosure (lua_State *L, Proto *l, int nelems) { | |||
116 | const TObject *luaV_gettable (lua_State *L, StkId t) { | 118 | const TObject *luaV_gettable (lua_State *L, StkId t) { |
117 | const TObject *im; | 119 | const TObject *im; |
118 | int tg; | 120 | int tg; |
119 | if (ttype(t) == TAG_TABLE && /* `t' is a table? */ | 121 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ |
120 | ((tg = hvalue(t)->htag) == TAG_TABLE || /* with default tag? */ | 122 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ |
121 | ttype(luaT_getim(L, tg, IM_GETTABLE)) == TAG_NIL)) { /* or no TM? */ | 123 | ttype(luaT_getim(L, tg, IM_GETTABLE)) == LUA_TNIL)) { /* or no TM? */ |
122 | /* do a primitive get */ | 124 | /* do a primitive get */ |
123 | const TObject *h = luaH_get(L, hvalue(t), L->top-1); | 125 | const TObject *h = luaH_get(L, hvalue(t), L->top-1); |
124 | /* result is no nil or there is no `index' tag method? */ | 126 | /* result is no nil or there is no `index' tag method? */ |
125 | if (ttype(h) != TAG_NIL || | 127 | if (ttype(h) != LUA_TNIL || |
126 | (ttype(im=luaT_getim(L, tg, IM_INDEX)) == TAG_NIL)) | 128 | (ttype(im=luaT_getim(L, tg, IM_INDEX)) == LUA_TNIL)) |
127 | return h; /* return result */ | 129 | return h; /* return result */ |
128 | /* else call `index' tag method */ | 130 | /* else call `index' tag method */ |
129 | } | 131 | } |
130 | else { /* try a 'gettable' TM */ | 132 | else { /* try a `gettable' tag method */ |
131 | im = luaT_getimbyObj(L, t, IM_GETTABLE); | 133 | im = luaT_getimbyObj(L, t, IM_GETTABLE); |
132 | } | 134 | } |
133 | if (ttype(im) != TAG_NIL) { /* is there a tag method? */ | 135 | if (ttype(im) != LUA_TNIL) { /* is there a tag method? */ |
134 | luaD_checkstack(L, 2); | 136 | luaD_checkstack(L, 2); |
135 | *(L->top+1) = *(L->top-1); /* key */ | 137 | *(L->top+1) = *(L->top-1); /* key */ |
136 | *L->top = *t; /* table */ | 138 | *L->top = *t; /* table */ |
@@ -151,13 +153,13 @@ const TObject *luaV_gettable (lua_State *L, StkId t) { | |||
151 | */ | 153 | */ |
152 | void luaV_settable (lua_State *L, StkId t, StkId key) { | 154 | void luaV_settable (lua_State *L, StkId t, StkId key) { |
153 | int tg; | 155 | int tg; |
154 | if (ttype(t) == TAG_TABLE && /* `t' is a table? */ | 156 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ |
155 | ((tg = hvalue(t)->htag) == TAG_TABLE || /* with default tag? */ | 157 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ |
156 | ttype(luaT_getim(L, tg, IM_SETTABLE)) == TAG_NIL)) /* or no TM? */ | 158 | ttype(luaT_getim(L, tg, IM_SETTABLE)) == LUA_TNIL)) /* or no TM? */ |
157 | *luaH_set(L, hvalue(t), key) = *(L->top-1); /* do a primitive set */ | 159 | *luaH_set(L, hvalue(t), key) = *(L->top-1); /* do a primitive set */ |
158 | else { /* try a `settable' tag method */ | 160 | else { /* try a `settable' tag method */ |
159 | const TObject *im = luaT_getimbyObj(L, t, IM_SETTABLE); | 161 | const TObject *im = luaT_getimbyObj(L, t, IM_SETTABLE); |
160 | if (ttype(im) != TAG_NIL) { | 162 | if (ttype(im) != LUA_TNIL) { |
161 | luaD_checkstack(L, 3); | 163 | luaD_checkstack(L, 3); |
162 | *(L->top+2) = *(L->top-1); | 164 | *(L->top+2) = *(L->top-1); |
163 | *(L->top+1) = *key; | 165 | *(L->top+1) = *key; |
@@ -175,12 +177,12 @@ void luaV_settable (lua_State *L, StkId t, StkId key) { | |||
175 | const TObject *luaV_getglobal (lua_State *L, TString *s) { | 177 | const TObject *luaV_getglobal (lua_State *L, TString *s) { |
176 | const TObject *value = luaH_getstr(L->gt, s); | 178 | const TObject *value = luaH_getstr(L->gt, s); |
177 | const TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); | 179 | const TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); |
178 | if (ttype(im) == TAG_NIL) /* is there a tag method? */ | 180 | if (ttype(im) == LUA_TNIL) /* is there a tag method? */ |
179 | return value; /* default behavior */ | 181 | return value; /* default behavior */ |
180 | else { /* tag method */ | 182 | else { /* tag method */ |
181 | luaD_checkstack(L, 3); | 183 | luaD_checkstack(L, 3); |
182 | *L->top = *im; | 184 | *L->top = *im; |
183 | ttype(L->top+1) = TAG_STRING; | 185 | ttype(L->top+1) = LUA_TSTRING; |
184 | tsvalue(L->top+1) = s; /* global name */ | 186 | tsvalue(L->top+1) = s; /* global name */ |
185 | *(L->top+2) = *value; | 187 | *(L->top+2) = *value; |
186 | L->top += 3; | 188 | L->top += 3; |
@@ -193,14 +195,14 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) { | |||
193 | void luaV_setglobal (lua_State *L, TString *s) { | 195 | void luaV_setglobal (lua_State *L, TString *s) { |
194 | const TObject *oldvalue = luaH_getstr(L->gt, s); | 196 | const TObject *oldvalue = luaH_getstr(L->gt, s); |
195 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); | 197 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); |
196 | if (ttype(im) == TAG_NIL) { /* is there a tag method? */ | 198 | if (ttype(im) == LUA_TNIL) { /* is there a tag method? */ |
197 | if (oldvalue != &luaO_nilobject) { | 199 | if (oldvalue != &luaO_nilobject) { |
198 | /* cast to remove `const' is OK, because `oldvalue' != luaO_nilobject */ | 200 | /* cast to remove `const' is OK, because `oldvalue' != luaO_nilobject */ |
199 | *(TObject *)oldvalue = *(L->top - 1); | 201 | *(TObject *)oldvalue = *(L->top - 1); |
200 | } | 202 | } |
201 | else { | 203 | else { |
202 | TObject key; | 204 | TObject key; |
203 | ttype(&key) = TAG_STRING; | 205 | ttype(&key) = LUA_TSTRING; |
204 | tsvalue(&key) = s; | 206 | tsvalue(&key) = s; |
205 | *luaH_set(L, L->gt, &key) = *(L->top - 1); | 207 | *luaH_set(L, L->gt, &key) = *(L->top - 1); |
206 | } | 208 | } |
@@ -209,7 +211,7 @@ void luaV_setglobal (lua_State *L, TString *s) { | |||
209 | luaD_checkstack(L, 3); | 211 | luaD_checkstack(L, 3); |
210 | *(L->top+2) = *(L->top-1); /* new value */ | 212 | *(L->top+2) = *(L->top-1); /* new value */ |
211 | *(L->top+1) = *oldvalue; | 213 | *(L->top+1) = *oldvalue; |
212 | ttype(L->top) = TAG_STRING; | 214 | ttype(L->top) = LUA_TSTRING; |
213 | tsvalue(L->top) = s; | 215 | tsvalue(L->top) = s; |
214 | *(L->top-1) = *im; | 216 | *(L->top-1) = *im; |
215 | L->top += 3; | 217 | L->top += 3; |
@@ -222,11 +224,11 @@ static int call_binTM (lua_State *L, StkId top, IMS event) { | |||
222 | /* try first operand */ | 224 | /* try first operand */ |
223 | const TObject *im = luaT_getimbyObj(L, top-2, event); | 225 | const TObject *im = luaT_getimbyObj(L, top-2, event); |
224 | L->top = top; | 226 | L->top = top; |
225 | if (ttype(im) == TAG_NIL) { | 227 | if (ttype(im) == LUA_TNIL) { |
226 | im = luaT_getimbyObj(L, top-1, event); /* try second operand */ | 228 | im = luaT_getimbyObj(L, top-1, event); /* try second operand */ |
227 | if (ttype(im) == TAG_NIL) { | 229 | if (ttype(im) == LUA_TNIL) { |
228 | im = luaT_getim(L, 0, event); /* try a `global' method */ | 230 | im = luaT_getim(L, 0, event); /* try a `global' method */ |
229 | if (ttype(im) == TAG_NIL) | 231 | if (ttype(im) == LUA_TNIL) |
230 | return 0; /* error */ | 232 | return 0; /* error */ |
231 | } | 233 | } |
232 | } | 234 | } |
@@ -238,7 +240,7 @@ static int call_binTM (lua_State *L, StkId top, IMS event) { | |||
238 | 240 | ||
239 | static void call_arith (lua_State *L, StkId top, IMS event) { | 241 | static void call_arith (lua_State *L, StkId top, IMS event) { |
240 | if (!call_binTM(L, top, event)) | 242 | if (!call_binTM(L, top, event)) |
241 | luaG_binerror(L, top-2, TAG_NUMBER, "perform arithmetic on"); | 243 | luaG_binerror(L, top-2, LUA_TNUMBER, "perform arithmetic on"); |
242 | } | 244 | } |
243 | 245 | ||
244 | 246 | ||
@@ -265,9 +267,9 @@ static int luaV_strcomp (const TString *ls, const TString *rs) { | |||
265 | 267 | ||
266 | 268 | ||
267 | int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) { | 269 | int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) { |
268 | if (ttype(l) == TAG_NUMBER && ttype(r) == TAG_NUMBER) | 270 | if (ttype(l) == LUA_TNUMBER && ttype(r) == LUA_TNUMBER) |
269 | return (nvalue(l) < nvalue(r)); | 271 | return (nvalue(l) < nvalue(r)); |
270 | else if (ttype(l) == TAG_STRING && ttype(r) == TAG_STRING) | 272 | else if (ttype(l) == LUA_TSTRING && ttype(r) == LUA_TSTRING) |
271 | return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0); | 273 | return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0); |
272 | else { /* call TM */ | 274 | else { /* call TM */ |
273 | luaD_checkstack(L, 2); | 275 | luaD_checkstack(L, 2); |
@@ -276,7 +278,7 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) | |||
276 | if (!call_binTM(L, top, IM_LT)) | 278 | if (!call_binTM(L, top, IM_LT)) |
277 | luaG_ordererror(L, top-2); | 279 | luaG_ordererror(L, top-2); |
278 | L->top--; | 280 | L->top--; |
279 | return (ttype(L->top) != TAG_NIL); | 281 | return (ttype(L->top) != LUA_TNIL); |
280 | } | 282 | } |
281 | } | 283 | } |
282 | 284 | ||
@@ -286,7 +288,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
286 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 288 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
287 | if (tostring(L, top-2) || tostring(L, top-1)) { | 289 | if (tostring(L, top-2) || tostring(L, top-1)) { |
288 | if (!call_binTM(L, top, IM_CONCAT)) | 290 | if (!call_binTM(L, top, IM_CONCAT)) |
289 | luaG_binerror(L, top-2, TAG_STRING, "concat"); | 291 | luaG_binerror(L, top-2, LUA_TSTRING, "concat"); |
290 | } | 292 | } |
291 | else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ | 293 | else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ |
292 | /* at least two string values; get as many as possible */ | 294 | /* at least two string values; get as many as possible */ |
@@ -322,7 +324,7 @@ static void luaV_pack (lua_State *L, StkId firstelem) { | |||
322 | /* store counter in field `n' */ | 324 | /* store counter in field `n' */ |
323 | luaH_setstrnum(L, htab, luaS_new(L, "n"), i); | 325 | luaH_setstrnum(L, htab, luaS_new(L, "n"), i); |
324 | L->top = firstelem; /* remove elements from the stack */ | 326 | L->top = firstelem; /* remove elements from the stack */ |
325 | ttype(L->top) = TAG_TABLE; | 327 | ttype(L->top) = LUA_TTABLE; |
326 | hvalue(L->top) = htab; | 328 | hvalue(L->top) = htab; |
327 | incr_top; | 329 | incr_top; |
328 | } | 330 | } |
@@ -393,7 +395,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
393 | int n = GETARG_U(i); | 395 | int n = GETARG_U(i); |
394 | LUA_ASSERT(n>0, "invalid argument"); | 396 | LUA_ASSERT(n>0, "invalid argument"); |
395 | do { | 397 | do { |
396 | ttype(top++) = TAG_NIL; | 398 | ttype(top++) = LUA_TNIL; |
397 | } while (--n > 0); | 399 | } while (--n > 0); |
398 | break; | 400 | break; |
399 | } | 401 | } |
@@ -402,25 +404,25 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
402 | break; | 404 | break; |
403 | } | 405 | } |
404 | case OP_PUSHINT: { | 406 | case OP_PUSHINT: { |
405 | ttype(top) = TAG_NUMBER; | 407 | ttype(top) = LUA_TNUMBER; |
406 | nvalue(top) = (Number)GETARG_S(i); | 408 | nvalue(top) = (Number)GETARG_S(i); |
407 | top++; | 409 | top++; |
408 | break; | 410 | break; |
409 | } | 411 | } |
410 | case OP_PUSHSTRING: { | 412 | case OP_PUSHSTRING: { |
411 | ttype(top) = TAG_STRING; | 413 | ttype(top) = LUA_TSTRING; |
412 | tsvalue(top) = kstr[GETARG_U(i)]; | 414 | tsvalue(top) = kstr[GETARG_U(i)]; |
413 | top++; | 415 | top++; |
414 | break; | 416 | break; |
415 | } | 417 | } |
416 | case OP_PUSHNUM: { | 418 | case OP_PUSHNUM: { |
417 | ttype(top) = TAG_NUMBER; | 419 | ttype(top) = LUA_TNUMBER; |
418 | nvalue(top) = tf->knum[GETARG_U(i)]; | 420 | nvalue(top) = tf->knum[GETARG_U(i)]; |
419 | top++; | 421 | top++; |
420 | break; | 422 | break; |
421 | } | 423 | } |
422 | case OP_PUSHNEGNUM: { | 424 | case OP_PUSHNEGNUM: { |
423 | ttype(top) = TAG_NUMBER; | 425 | ttype(top) = LUA_TNUMBER; |
424 | nvalue(top) = -tf->knum[GETARG_U(i)]; | 426 | nvalue(top) = -tf->knum[GETARG_U(i)]; |
425 | top++; | 427 | top++; |
426 | break; | 428 | break; |
@@ -446,7 +448,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
446 | break; | 448 | break; |
447 | } | 449 | } |
448 | case OP_GETDOTTED: { | 450 | case OP_GETDOTTED: { |
449 | ttype(top) = TAG_STRING; | 451 | ttype(top) = LUA_TSTRING; |
450 | tsvalue(top) = kstr[GETARG_U(i)]; | 452 | tsvalue(top) = kstr[GETARG_U(i)]; |
451 | L->top = top+1; | 453 | L->top = top+1; |
452 | *(top-1) = *luaV_gettable(L, top-1); | 454 | *(top-1) = *luaV_gettable(L, top-1); |
@@ -461,7 +463,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
461 | case OP_PUSHSELF: { | 463 | case OP_PUSHSELF: { |
462 | TObject receiver; | 464 | TObject receiver; |
463 | receiver = *(top-1); | 465 | receiver = *(top-1); |
464 | ttype(top) = TAG_STRING; | 466 | ttype(top) = LUA_TSTRING; |
465 | tsvalue(top++) = kstr[GETARG_U(i)]; | 467 | tsvalue(top++) = kstr[GETARG_U(i)]; |
466 | L->top = top; | 468 | L->top = top; |
467 | *(top-2) = *luaV_gettable(L, top-2); | 469 | *(top-2) = *luaV_gettable(L, top-2); |
@@ -472,7 +474,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
472 | L->top = top; | 474 | L->top = top; |
473 | luaC_checkGC(L); | 475 | luaC_checkGC(L); |
474 | hvalue(top) = luaH_new(L, GETARG_U(i)); | 476 | hvalue(top) = luaH_new(L, GETARG_U(i)); |
475 | ttype(top) = TAG_TABLE; | 477 | ttype(top) = LUA_TTABLE; |
476 | top++; | 478 | top++; |
477 | break; | 479 | break; |
478 | } | 480 | } |
@@ -523,7 +525,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
523 | } | 525 | } |
524 | case OP_ADDI: { | 526 | case OP_ADDI: { |
525 | if (tonumber(top-1)) { | 527 | if (tonumber(top-1)) { |
526 | ttype(top) = TAG_NUMBER; | 528 | ttype(top) = LUA_TNUMBER; |
527 | nvalue(top) = (Number)GETARG_S(i); | 529 | nvalue(top) = (Number)GETARG_S(i); |
528 | call_arith(L, top+1, IM_ADD); | 530 | call_arith(L, top+1, IM_ADD); |
529 | } | 531 | } |
@@ -571,7 +573,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
571 | } | 573 | } |
572 | case OP_MINUS: { | 574 | case OP_MINUS: { |
573 | if (tonumber(top-1)) { | 575 | if (tonumber(top-1)) { |
574 | ttype(top) = TAG_NIL; | 576 | ttype(top) = LUA_TNIL; |
575 | call_arith(L, top+1, IM_UNM); | 577 | call_arith(L, top+1, IM_UNM); |
576 | } | 578 | } |
577 | else | 579 | else |
@@ -580,7 +582,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
580 | } | 582 | } |
581 | case OP_NOT: { | 583 | case OP_NOT: { |
582 | ttype(top-1) = | 584 | ttype(top-1) = |
583 | (ttype(top-1) == TAG_NIL) ? TAG_NUMBER : TAG_NIL; | 585 | (ttype(top-1) == LUA_TNIL) ? LUA_TNUMBER : LUA_TNIL; |
584 | nvalue(top-1) = 1; | 586 | nvalue(top-1) = 1; |
585 | break; | 587 | break; |
586 | } | 588 | } |
@@ -615,20 +617,20 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
615 | break; | 617 | break; |
616 | } | 618 | } |
617 | case OP_JMPT: { | 619 | case OP_JMPT: { |
618 | if (ttype(--top) != TAG_NIL) dojump(pc, i); | 620 | if (ttype(--top) != LUA_TNIL) dojump(pc, i); |
619 | break; | 621 | break; |
620 | } | 622 | } |
621 | case OP_JMPF: { | 623 | case OP_JMPF: { |
622 | if (ttype(--top) == TAG_NIL) dojump(pc, i); | 624 | if (ttype(--top) == LUA_TNIL) dojump(pc, i); |
623 | break; | 625 | break; |
624 | } | 626 | } |
625 | case OP_JMPONT: { | 627 | case OP_JMPONT: { |
626 | if (ttype(top-1) == TAG_NIL) top--; | 628 | if (ttype(top-1) == LUA_TNIL) top--; |
627 | else dojump(pc, i); | 629 | else dojump(pc, i); |
628 | break; | 630 | break; |
629 | } | 631 | } |
630 | case OP_JMPONF: { | 632 | case OP_JMPONF: { |
631 | if (ttype(top-1) != TAG_NIL) top--; | 633 | if (ttype(top-1) != LUA_TNIL) top--; |
632 | else dojump(pc, i); | 634 | else dojump(pc, i); |
633 | break; | 635 | break; |
634 | } | 636 | } |
@@ -637,7 +639,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
637 | break; | 639 | break; |
638 | } | 640 | } |
639 | case OP_PUSHNILJMP: { | 641 | case OP_PUSHNILJMP: { |
640 | ttype(top++) = TAG_NIL; | 642 | ttype(top++) = LUA_TNIL; |
641 | pc++; | 643 | pc++; |
642 | break; | 644 | break; |
643 | } | 645 | } |
@@ -657,9 +659,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
657 | break; | 659 | break; |
658 | } | 660 | } |
659 | case OP_FORLOOP: { | 661 | case OP_FORLOOP: { |
660 | LUA_ASSERT(ttype(top-1) == TAG_NUMBER, "invalid step"); | 662 | LUA_ASSERT(ttype(top-1) == LUA_TNUMBER, "invalid step"); |
661 | LUA_ASSERT(ttype(top-2) == TAG_NUMBER, "invalid limit"); | 663 | LUA_ASSERT(ttype(top-2) == LUA_TNUMBER, "invalid limit"); |
662 | if (ttype(top-3) != TAG_NUMBER) | 664 | if (ttype(top-3) != LUA_TNUMBER) |
663 | lua_error(L, "`for' index must be a number"); | 665 | lua_error(L, "`for' index must be a number"); |
664 | nvalue(top-3) += nvalue(top-1); /* increment index */ | 666 | nvalue(top-3) += nvalue(top-1); /* increment index */ |
665 | if (nvalue(top-1) > 0 ? | 667 | if (nvalue(top-1) > 0 ? |
@@ -672,7 +674,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
672 | } | 674 | } |
673 | case OP_LFORPREP: { | 675 | case OP_LFORPREP: { |
674 | Node *node; | 676 | Node *node; |
675 | if (ttype(top-1) != TAG_TABLE) | 677 | if (ttype(top-1) != LUA_TTABLE) |
676 | lua_error(L, "`for' table must be a table"); | 678 | lua_error(L, "`for' table must be a table"); |
677 | node = luaH_next(L, hvalue(top-1), &luaO_nilobject); | 679 | node = luaH_next(L, hvalue(top-1), &luaO_nilobject); |
678 | if (node == NULL) { /* `empty' loop? */ | 680 | if (node == NULL) { /* `empty' loop? */ |
@@ -688,7 +690,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
688 | } | 690 | } |
689 | case OP_LFORLOOP: { | 691 | case OP_LFORLOOP: { |
690 | Node *node; | 692 | Node *node; |
691 | LUA_ASSERT(ttype(top-3) == TAG_TABLE, "invalid table"); | 693 | LUA_ASSERT(ttype(top-3) == LUA_TTABLE, "invalid table"); |
692 | node = luaH_next(L, hvalue(top-3), top-2); | 694 | node = luaH_next(L, hvalue(top-3), top-2); |
693 | if (node == NULL) /* end loop? */ | 695 | if (node == NULL) /* end loop? */ |
694 | top -= 3; /* remove table, key, and value */ | 696 | top -= 3; /* remove table, key, and value */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 1.25 2000/08/31 21:02:55 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 1.26 2000/09/05 19:33:32 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -13,8 +13,8 @@ | |||
13 | #include "ltm.h" | 13 | #include "ltm.h" |
14 | 14 | ||
15 | 15 | ||
16 | #define tonumber(o) ((ttype(o) != TAG_NUMBER) && (luaV_tonumber(o) != 0)) | 16 | #define tonumber(o) ((ttype(o) != LUA_TNUMBER) && (luaV_tonumber(o) != 0)) |
17 | #define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0)) | 17 | #define tostring(L,o) ((ttype(o) != LUA_TSTRING) && (luaV_tostring(L, o) != 0)) |
18 | 18 | ||
19 | 19 | ||
20 | int luaV_tonumber (TObject *obj); | 20 | int luaV_tonumber (TObject *obj); |