aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 502c70c8..d57f9fa2 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.105 2000/04/14 17:44:20 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.106 2000/04/17 19:23:12 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*/
@@ -321,7 +321,7 @@ void luaB_call (lua_State *L) {
321 /* push arg[1...n] */ 321 /* push arg[1...n] */
322 luaD_checkstack(L, narg); 322 luaD_checkstack(L, narg);
323 for (i=0; i<narg; i++) 323 for (i=0; i<narg; i++)
324 *(L->top++) = *luaH_getint(L, arg, i+1); 324 *(L->top++) = *luaH_getnum(arg, i+1);
325 status = lua_callfunction(L, f); 325 status = lua_callfunction(L, f);
326 if (err != LUA_NOOBJECT) { /* restore old error method */ 326 if (err != LUA_NOOBJECT) { /* restore old error method */
327 lua_pushobject(L, err); 327 lua_pushobject(L, err);
@@ -434,7 +434,7 @@ void luaB_foreachi (lua_State *L) {
434 for (i=1; i<=n; i++) { 434 for (i=1; i<=n; i++) {
435 *(L->top++) = *f; 435 *(L->top++) = *f;
436 ttype(L->top) = TAG_NUMBER; nvalue(L->top++) = i; 436 ttype(L->top) = TAG_NUMBER; nvalue(L->top++) = i;
437 *(L->top++) = *luaH_getint(L, t, i); 437 *(L->top++) = *luaH_getnum(t, i);
438 luaD_call(L, L->top-3, 1); 438 luaD_call(L, L->top-3, 1);
439 if (ttype(L->top-1) != TAG_NIL) 439 if (ttype(L->top-1) != TAG_NIL)
440 return; 440 return;
@@ -513,7 +513,7 @@ void luaB_tremove (lua_State *L) {
513 int n = (int)getnarg(L, a); 513 int n = (int)getnarg(L, a);
514 int pos = luaL_opt_int(L, 2, n); 514 int pos = luaL_opt_int(L, 2, n);
515 if (n <= 0) return; /* table is "empty" */ 515 if (n <= 0) return; /* table is "empty" */
516 luaA_pushobject(L, luaH_getint(L, a, pos)); /* result = a[pos] */ 516 luaA_pushobject(L, luaH_getnum(a, pos)); /* result = a[pos] */
517 for ( ;pos<n; pos++) 517 for ( ;pos<n; pos++)
518 luaH_move(L, a, pos+1, pos); /* a[pos] = a[pos+1] */ 518 luaH_move(L, a, pos+1, pos); /* a[pos] = a[pos+1] */
519 luaV_setn(L, a, n-1); /* a.n = n-1 */ 519 luaV_setn(L, a, n-1); /* a.n = n-1 */
@@ -529,7 +529,7 @@ void luaB_tremove (lua_State *L) {
529 529
530static void swap (lua_State *L, Hash *a, int i, int j) { 530static void swap (lua_State *L, Hash *a, int i, int j) {
531 TObject temp; 531 TObject temp;
532 temp = *luaH_getint(L, a, i); 532 temp = *luaH_getnum(a, i);
533 luaH_move(L, a, j, i); 533 luaH_move(L, a, j, i);
534 luaH_setint(L, a, j, &temp); 534 luaH_setint(L, a, j, &temp);
535} 535}
@@ -556,26 +556,26 @@ static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) {
556 while (l < u) { /* for tail recursion */ 556 while (l < u) { /* for tail recursion */
557 int i, j; 557 int i, j;
558 /* sort elements a[l], a[(l+u)/2] and a[u] */ 558 /* sort elements a[l], a[(l+u)/2] and a[u] */
559 if (sort_comp(L, f, luaH_getint(L, a, u), luaH_getint(L, a, l))) 559 if (sort_comp(L, f, luaH_getnum(a, u), luaH_getnum(a, l)))
560 swap(L, a, l, u); /* a[u]<a[l] */ 560 swap(L, a, l, u); /* a[u]<a[l] */
561 if (u-l == 1) break; /* only 2 elements */ 561 if (u-l == 1) break; /* only 2 elements */
562 i = (l+u)/2; 562 i = (l+u)/2;
563 *P = *luaH_getint(L, a, i); /* P = a[i] */ 563 *P = *luaH_getnum(a, i); /* P = a[i] */
564 if (sort_comp(L, f, P, luaH_getint(L, a, l))) /* a[i]<a[l]? */ 564 if (sort_comp(L, f, P, luaH_getnum(a, l))) /* a[i]<a[l]? */
565 swap(L, a, l, i); 565 swap(L, a, l, i);
566 else if (sort_comp(L, f, luaH_getint(L, a, u), P)) /* a[u]<a[i]? */ 566 else if (sort_comp(L, f, luaH_getnum(a, u), P)) /* a[u]<a[i]? */
567 swap(L, a, i, u); 567 swap(L, a, i, u);
568 if (u-l == 2) break; /* only 3 elements */ 568 if (u-l == 2) break; /* only 3 elements */
569 *P = *luaH_getint(L, a, i); /* save pivot on stack (GC) */ 569 *P = *luaH_getnum(a, i); /* save pivot on stack (GC) */
570 swap(L, a, i, u-1); /* put median element as pivot (a[u-1]) */ 570 swap(L, a, i, u-1); /* put median element as pivot (a[u-1]) */
571 /* a[l] <= P == a[u-1] <= a[u], only needs to sort from l+1 to u-2 */ 571 /* a[l] <= P == a[u-1] <= a[u], only needs to sort from l+1 to u-2 */
572 i = l; j = u-1; 572 i = l; j = u-1;
573 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ 573 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
574 /* repeat i++ until a[i] >= P */ 574 /* repeat i++ until a[i] >= P */
575 while (sort_comp(L, f, luaH_getint(L, a, ++i), P)) 575 while (sort_comp(L, f, luaH_getnum(a, ++i), P))
576 if (i>u) lua_error(L, "invalid order function for sorting"); 576 if (i>u) lua_error(L, "invalid order function for sorting");
577 /* repeat j-- until a[j] <= P */ 577 /* repeat j-- until a[j] <= P */
578 while (sort_comp(L, f, P, luaH_getint(L, a, --j))) 578 while (sort_comp(L, f, P, luaH_getnum(a, --j)))
579 if (j<l) lua_error(L, "invalid order function for sorting"); 579 if (j<l) lua_error(L, "invalid order function for sorting");
580 if (j<i) break; 580 if (j<i) break;
581 swap(L, a, i, j); 581 swap(L, a, i, j);