aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 19cdb6d6..ac45f361 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.112 2000/06/02 19:08:56 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.113 2000/06/05 20:15:33 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*/
@@ -402,6 +402,13 @@ void luaB_getn (lua_State *L) {
402} 402}
403 403
404 404
405/* auxiliar function */
406static void t_move (lua_State *L, Hash *t, int from, int to) {
407 TObject *p = luaH_setint(L, t, to); /* may change following `get' */
408 *p = *luaH_getnum(t, from);
409}
410
411
405void luaB_tinsert (lua_State *L) { 412void luaB_tinsert (lua_State *L) {
406 Hash *a = gettable(L, 1); 413 Hash *a = gettable(L, 1);
407 lua_Object v = lua_getparam(L, 3); 414 lua_Object v = lua_getparam(L, 3);
@@ -413,10 +420,10 @@ void luaB_tinsert (lua_State *L) {
413 v = luaL_nonnullarg(L, 2); 420 v = luaL_nonnullarg(L, 2);
414 pos = n+1; 421 pos = n+1;
415 } 422 }
416 luaV_setn(L, a, n+1); /* a.n = n+1 */ 423 luaH_setstrnum(L, a, luaS_new(L, "n"), n+1); /* a.n = n+1 */
417 for (; n>=pos; n--) 424 for (; n>=pos; n--)
418 luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */ 425 t_move(L, a, n, n+1); /* a[n+1] = a[n] */
419 luaH_setint(L, a, pos, v); /* a[pos] = v */ 426 *luaH_setint(L, a, pos) = *v; /* a[pos] = v */
420} 427}
421 428
422 429
@@ -427,9 +434,9 @@ void luaB_tremove (lua_State *L) {
427 if (n <= 0) return; /* table is "empty" */ 434 if (n <= 0) return; /* table is "empty" */
428 luaA_pushobject(L, luaH_getnum(a, pos)); /* result = a[pos] */ 435 luaA_pushobject(L, luaH_getnum(a, pos)); /* result = a[pos] */
429 for ( ;pos<n; pos++) 436 for ( ;pos<n; pos++)
430 luaH_move(L, a, pos+1, pos); /* a[pos] = a[pos+1] */ 437 t_move(L, a, pos+1, pos); /* a[pos] = a[pos+1] */
431 luaV_setn(L, a, n-1); /* a.n = n-1 */ 438 luaH_setstrnum(L, a, luaS_new(L, "n"), n-1); /* a.n = n-1 */
432 luaH_setint(L, a, n, &luaO_nilobject); /* a[n] = nil */ 439 ttype(luaH_setint(L, a, n)) = TAG_NIL; /* a[n] = nil */
433} 440}
434 441
435 442
@@ -478,11 +485,12 @@ static void luaB_foreach (lua_State *L) {
478** Addison-Wesley, 1993.) 485** Addison-Wesley, 1993.)
479*/ 486*/
480 487
488
481static void swap (lua_State *L, Hash *a, int i, int j) { 489static void swap (lua_State *L, Hash *a, int i, int j) {
482 TObject temp; 490 TObject temp;
483 temp = *luaH_getnum(a, i); 491 temp = *luaH_getnum(a, i);
484 luaH_move(L, a, j, i); 492 t_move(L, a, j, i);
485 luaH_setint(L, a, j, &temp); 493 *luaH_setint(L, a, j) = temp;
486} 494}
487 495
488static int sort_comp (lua_State *L, lua_Object f, const TObject *a, 496static int sort_comp (lua_State *L, lua_Object f, const TObject *a,