diff options
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 64 |
1 files changed, 32 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.94 2000/03/03 14:58:26 roberto Exp $ | 2 | ** $Id: lbuiltin.c,v 1.95 2000/03/09 00:19:22 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -52,20 +52,20 @@ void luaB_opentests (lua_State *L); | |||
52 | */ | 52 | */ |
53 | 53 | ||
54 | 54 | ||
55 | static void pushtagstring (lua_State *L, TaggedString *s) { | 55 | static void pushtagstring (lua_State *L, TString *s) { |
56 | ttype(L->top) = LUA_T_STRING; | 56 | ttype(L->top) = TAG_STRING; |
57 | tsvalue(L->top) = s; | 57 | tsvalue(L->top) = s; |
58 | incr_top; | 58 | incr_top; |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | static real getsize (const Hash *h) { | 62 | static Number getsize (const Hash *h) { |
63 | real max = 0; | 63 | Number max = 0; |
64 | int i = h->size; | 64 | int i = h->size; |
65 | Node *n = h->node; | 65 | Node *n = h->node; |
66 | while (i--) { | 66 | while (i--) { |
67 | if (ttype(key(n)) == LUA_T_NUMBER && | 67 | if (ttype(key(n)) == TAG_NUMBER && |
68 | ttype(val(n)) != LUA_T_NIL && | 68 | ttype(val(n)) != TAG_NIL && |
69 | nvalue(key(n)) > max) | 69 | nvalue(key(n)) > max) |
70 | max = nvalue(key(n)); | 70 | max = nvalue(key(n)); |
71 | n++; | 71 | n++; |
@@ -74,14 +74,14 @@ static real getsize (const Hash *h) { | |||
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static real getnarg (lua_State *L, const Hash *a) { | 77 | static Number getnarg (lua_State *L, const Hash *a) { |
78 | TObject index; | 78 | TObject index; |
79 | const TObject *value; | 79 | const TObject *value; |
80 | /* value = table.n */ | 80 | /* value = table.n */ |
81 | ttype(&index) = LUA_T_STRING; | 81 | ttype(&index) = TAG_STRING; |
82 | tsvalue(&index) = luaS_new(L, "n"); | 82 | tsvalue(&index) = luaS_new(L, "n"); |
83 | value = luaH_get(L, a, &index); | 83 | value = luaH_get(L, a, &index); |
84 | return (ttype(value) == LUA_T_NUMBER) ? nvalue(value) : getsize(a); | 84 | return (ttype(value) == TAG_NUMBER) ? nvalue(value) : getsize(a); |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
@@ -167,7 +167,7 @@ void luaB_tonumber (lua_State *L) { | |||
167 | else { | 167 | else { |
168 | const char *s1 = luaL_check_string(L, 1); | 168 | const char *s1 = luaL_check_string(L, 1); |
169 | char *s2; | 169 | char *s2; |
170 | real n; | 170 | Number n; |
171 | luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range"); | 171 | luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range"); |
172 | n = strtoul(s1, &s2, base); | 172 | n = strtoul(s1, &s2, base); |
173 | if (s1 == s2) return; /* no valid digits: return nil */ | 173 | if (s1 == s2) return; /* no valid digits: return nil */ |
@@ -244,7 +244,7 @@ void luaB_settagmethod (lua_State *L) { | |||
244 | luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, | 244 | luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, |
245 | "function or nil expected"); | 245 | "function or nil expected"); |
246 | #ifndef LUA_COMPAT_GC | 246 | #ifndef LUA_COMPAT_GC |
247 | if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) | 247 | if (strcmp(event, "gc") == 0 && tag != TAG_NIL) |
248 | lua_error(L, "cannot set this `gc' tag method from Lua"); | 248 | lua_error(L, "cannot set this `gc' tag method from Lua"); |
249 | #endif | 249 | #endif |
250 | lua_pushobject(L, nf); | 250 | lua_pushobject(L, nf); |
@@ -349,11 +349,11 @@ void luaB_call (lua_State *L) { | |||
349 | 349 | ||
350 | void luaB_nextvar (lua_State *L) { | 350 | void luaB_nextvar (lua_State *L) { |
351 | lua_Object o = luaL_nonnullarg(L, 1); | 351 | lua_Object o = luaL_nonnullarg(L, 1); |
352 | TaggedString *name; | 352 | TString *name; |
353 | if (ttype(o) == LUA_T_NIL) | 353 | if (ttype(o) == TAG_NIL) |
354 | name = NULL; | 354 | name = NULL; |
355 | else { | 355 | else { |
356 | luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected"); | 356 | luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "variable name expected"); |
357 | name = tsvalue(o); | 357 | name = tsvalue(o); |
358 | } | 358 | } |
359 | if (!luaA_nextvar(L, name)) | 359 | if (!luaA_nextvar(L, name)) |
@@ -365,7 +365,7 @@ void luaB_next (lua_State *L) { | |||
365 | const Hash *a = gettable(L, 1); | 365 | const Hash *a = gettable(L, 1); |
366 | lua_Object k = luaL_nonnullarg(L, 2); | 366 | lua_Object k = luaL_nonnullarg(L, 2); |
367 | int i; /* `luaA_next' gets first element after `i' */ | 367 | int i; /* `luaA_next' gets first element after `i' */ |
368 | if (ttype(k) == LUA_T_NIL) | 368 | if (ttype(k) == TAG_NIL) |
369 | i = 0; /* get first */ | 369 | i = 0; /* get first */ |
370 | else { | 370 | else { |
371 | i = luaH_pos(L, a, k)+1; | 371 | i = luaH_pos(L, a, k)+1; |
@@ -380,29 +380,29 @@ void luaB_tostring (lua_State *L) { | |||
380 | lua_Object o = lua_getparam(L, 1); | 380 | lua_Object o = lua_getparam(L, 1); |
381 | char buff[64]; | 381 | char buff[64]; |
382 | switch (ttype(o)) { | 382 | switch (ttype(o)) { |
383 | case LUA_T_NUMBER: | 383 | case TAG_NUMBER: |
384 | lua_pushstring(L, lua_getstring(L, o)); | 384 | lua_pushstring(L, lua_getstring(L, o)); |
385 | return; | 385 | return; |
386 | case LUA_T_STRING: | 386 | case TAG_STRING: |
387 | lua_pushobject(L, o); | 387 | lua_pushobject(L, o); |
388 | return; | 388 | return; |
389 | case LUA_T_ARRAY: | 389 | case TAG_ARRAY: |
390 | sprintf(buff, "table: %p", o->value.a); | 390 | sprintf(buff, "table: %p", o->value.a); |
391 | break; | 391 | break; |
392 | case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: | 392 | case TAG_LCLOSURE: case TAG_CCLOSURE: |
393 | sprintf(buff, "function: %p", o->value.cl); | 393 | sprintf(buff, "function: %p", o->value.cl); |
394 | break; | 394 | break; |
395 | case LUA_T_LPROTO: | 395 | case TAG_LPROTO: |
396 | sprintf(buff, "function: %p", o->value.tf); | 396 | sprintf(buff, "function: %p", o->value.tf); |
397 | break; | 397 | break; |
398 | case LUA_T_CPROTO: | 398 | case TAG_CPROTO: |
399 | sprintf(buff, "function: %p", o->value.f); | 399 | sprintf(buff, "function: %p", o->value.f); |
400 | break; | 400 | break; |
401 | case LUA_T_USERDATA: | 401 | case TAG_USERDATA: |
402 | sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value, | 402 | sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value, |
403 | o->value.ts->u.d.tag); | 403 | o->value.ts->u.d.tag); |
404 | break; | 404 | break; |
405 | case LUA_T_NIL: | 405 | case TAG_NIL: |
406 | lua_pushstring(L, "nil"); | 406 | lua_pushstring(L, "nil"); |
407 | return; | 407 | return; |
408 | default: | 408 | default: |
@@ -440,10 +440,10 @@ void luaB_foreachi (lua_State *L) { | |||
440 | luaD_checkstack(L, 3); /* for f, key, and val */ | 440 | luaD_checkstack(L, 3); /* for f, key, and val */ |
441 | for (i=1; i<=n; i++) { | 441 | for (i=1; i<=n; i++) { |
442 | *(L->top++) = *f; | 442 | *(L->top++) = *f; |
443 | ttype(L->top) = LUA_T_NUMBER; nvalue(L->top++) = i; | 443 | ttype(L->top) = TAG_NUMBER; nvalue(L->top++) = i; |
444 | *(L->top++) = *luaH_getint(L, t, i); | 444 | *(L->top++) = *luaH_getint(L, t, i); |
445 | luaD_call(L, L->top-3, 1); | 445 | luaD_call(L, L->top-3, 1); |
446 | if (ttype(L->top-1) != LUA_T_NIL) | 446 | if (ttype(L->top-1) != TAG_NIL) |
447 | return; | 447 | return; |
448 | L->top--; /* remove nil result */ | 448 | L->top--; /* remove nil result */ |
449 | } | 449 | } |
@@ -457,12 +457,12 @@ void luaB_foreach (lua_State *L) { | |||
457 | luaD_checkstack(L, 3); /* for f, key, and val */ | 457 | luaD_checkstack(L, 3); /* for f, key, and val */ |
458 | for (i=0; i<a->size; i++) { | 458 | for (i=0; i<a->size; i++) { |
459 | const Node *nd = &(a->node[i]); | 459 | const Node *nd = &(a->node[i]); |
460 | if (ttype(val(nd)) != LUA_T_NIL) { | 460 | if (ttype(val(nd)) != TAG_NIL) { |
461 | *(L->top++) = *f; | 461 | *(L->top++) = *f; |
462 | *(L->top++) = *key(nd); | 462 | *(L->top++) = *key(nd); |
463 | *(L->top++) = *val(nd); | 463 | *(L->top++) = *val(nd); |
464 | luaD_call(L, L->top-3, 1); | 464 | luaD_call(L, L->top-3, 1); |
465 | if (ttype(L->top-1) != LUA_T_NIL) | 465 | if (ttype(L->top-1) != TAG_NIL) |
466 | return; | 466 | return; |
467 | L->top--; /* remove result */ | 467 | L->top--; /* remove result */ |
468 | } | 468 | } |
@@ -475,13 +475,13 @@ void luaB_foreachvar (lua_State *L) { | |||
475 | GlobalVar *gv; | 475 | GlobalVar *gv; |
476 | luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ | 476 | luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ |
477 | for (gv = L->rootglobal; gv; gv = gv->next) { | 477 | for (gv = L->rootglobal; gv; gv = gv->next) { |
478 | if (gv->value.ttype != LUA_T_NIL) { | 478 | if (gv->value.ttype != TAG_NIL) { |
479 | pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */ | 479 | pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */ |
480 | *(L->top++) = *f; | 480 | *(L->top++) = *f; |
481 | pushtagstring(L, gv->name); | 481 | pushtagstring(L, gv->name); |
482 | *(L->top++) = gv->value; | 482 | *(L->top++) = gv->value; |
483 | luaD_call(L, L->top-3, 1); | 483 | luaD_call(L, L->top-3, 1); |
484 | if (ttype(L->top-1) != LUA_T_NIL) { | 484 | if (ttype(L->top-1) != TAG_NIL) { |
485 | *(L->top-2) = *(L->top-1); /* remove extra name */ | 485 | *(L->top-2) = *(L->top-1); /* remove extra name */ |
486 | L->top--; | 486 | L->top--; |
487 | return; | 487 | return; |
@@ -551,7 +551,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a, | |||
551 | L->top += 3; | 551 | L->top += 3; |
552 | luaD_call(L, L->top-3, 1); | 552 | luaD_call(L, L->top-3, 1); |
553 | L->top--; | 553 | L->top--; |
554 | return (ttype(L->top) != LUA_T_NIL); | 554 | return (ttype(L->top) != TAG_NIL); |
555 | } | 555 | } |
556 | else /* a < b? */ | 556 | else /* a < b? */ |
557 | return luaV_lessthan(L, a, b, L->top); | 557 | return luaV_lessthan(L, a, b, L->top); |
@@ -559,7 +559,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a, | |||
559 | 559 | ||
560 | static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) { | 560 | static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) { |
561 | StkId P = L->top++; /* temporary place for pivot */ | 561 | StkId P = L->top++; /* temporary place for pivot */ |
562 | ttype(P) = LUA_T_NIL; | 562 | ttype(P) = TAG_NIL; |
563 | while (l < u) { /* for tail recursion */ | 563 | while (l < u) { /* for tail recursion */ |
564 | int i, j; | 564 | int i, j; |
565 | /* sort elements a[l], a[(l+u)/2] and a[u] */ | 565 | /* sort elements a[l], a[(l+u)/2] and a[u] */ |