From 5caf7f4a33938f482be78d1b4a807e86411706f0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 27 May 1999 17:21:03 -0300 Subject: tremove erases its previous last element (to avoid locking potential garbagge). --- lbuiltin.c | 15 ++++++++------- manual.tex | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lbuiltin.c b/lbuiltin.c index 9d8e018d..077bcc46 100644 --- a/lbuiltin.c +++ b/lbuiltin.c @@ -1,5 +1,5 @@ /* -** $Id: lbuiltin.c,v 1.56 1999/03/04 21:17:26 roberto Exp roberto $ +** $Id: lbuiltin.c,v 1.57 1999/05/24 17:53:49 roberto Exp roberto $ ** Built-in functions ** See Copyright Notice in lua.h */ @@ -470,10 +470,10 @@ static void luaB_tinsert (void) { v = luaL_nonnullarg(2); pos = n+1; } - luaV_setn(a, n+1); /* increment field "n" */ + luaV_setn(a, n+1); /* a.n = n+1 */ for ( ;n>=pos; n--) - luaH_move(a, n, n+1); - luaH_setint(a, pos, luaA_Address(v)); + luaH_move(a, n, n+1); /* a[n+1] = a[n] */ + luaH_setint(a, pos, luaA_Address(v)); /* a[pos] = v */ } @@ -482,10 +482,11 @@ static void luaB_tremove (void) { int n = (int)getnarg(a); int pos = luaL_opt_int(2, n); if (n <= 0) return; /* table is "empty" */ - luaA_pushobject(luaH_getint(a, pos)); /* push result */ - luaV_setn(a, n-1); /* decrement field "n" */ + luaA_pushobject(luaH_getint(a, pos)); /* result = a[pos] */ for ( ;pos