diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-05-27 17:21:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-05-27 17:21:03 -0300 |
commit | 5caf7f4a33938f482be78d1b4a807e86411706f0 (patch) | |
tree | a476505262d12001e3026583804dd4369503e452 | |
parent | 3b533ea7c7fd65c2c2e61cd4c0a00578152e450a (diff) | |
download | lua-5caf7f4a33938f482be78d1b4a807e86411706f0.tar.gz lua-5caf7f4a33938f482be78d1b4a807e86411706f0.tar.bz2 lua-5caf7f4a33938f482be78d1b4a807e86411706f0.zip |
tremove erases its previous last element (to avoid locking potential
garbagge).
-rw-r--r-- | lbuiltin.c | 15 | ||||
-rw-r--r-- | manual.tex | 7 |
2 files changed, 12 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.56 1999/03/04 21:17:26 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.57 1999/05/24 17:53:49 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 | */ |
@@ -470,10 +470,10 @@ static void luaB_tinsert (void) { | |||
470 | v = luaL_nonnullarg(2); | 470 | v = luaL_nonnullarg(2); |
471 | pos = n+1; | 471 | pos = n+1; |
472 | } | 472 | } |
473 | luaV_setn(a, n+1); /* increment field "n" */ | 473 | luaV_setn(a, n+1); /* a.n = n+1 */ |
474 | for ( ;n>=pos; n--) | 474 | for ( ;n>=pos; n--) |
475 | luaH_move(a, n, n+1); | 475 | luaH_move(a, n, n+1); /* a[n+1] = a[n] */ |
476 | luaH_setint(a, pos, luaA_Address(v)); | 476 | luaH_setint(a, pos, luaA_Address(v)); /* a[pos] = v */ |
477 | } | 477 | } |
478 | 478 | ||
479 | 479 | ||
@@ -482,10 +482,11 @@ static void luaB_tremove (void) { | |||
482 | int n = (int)getnarg(a); | 482 | int n = (int)getnarg(a); |
483 | int pos = luaL_opt_int(2, n); | 483 | int pos = luaL_opt_int(2, n); |
484 | if (n <= 0) return; /* table is "empty" */ | 484 | if (n <= 0) return; /* table is "empty" */ |
485 | luaA_pushobject(luaH_getint(a, pos)); /* push result */ | 485 | luaA_pushobject(luaH_getint(a, pos)); /* result = a[pos] */ |
486 | luaV_setn(a, n-1); /* decrement field "n" */ | ||
487 | for ( ;pos<n; pos++) | 486 | for ( ;pos<n; pos++) |
488 | luaH_move(a, pos+1, pos); | 487 | luaH_move(a, pos+1, pos); /* a[pos] = a[pos+1] */ |
488 | luaV_setn(a, n-1); /* a.n = n-1 */ | ||
489 | luaH_setint(a, n, &luaO_nilobject); /* a[n] = nil */ | ||
489 | } | 490 | } |
490 | 491 | ||
491 | 492 | ||
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 1.31 1999/05/05 19:21:57 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.32 1999/05/11 20:46:28 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentclass[11pt]{article} | 3 | \documentclass[11pt]{article} |
4 | \usepackage{fullpage,bnf} | 4 | \usepackage{fullpage,bnf} |
@@ -41,7 +41,7 @@ Waldemar Celes | |||
41 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
42 | } | 42 | } |
43 | 43 | ||
44 | \date{{\small \tt\$Date: 1999/05/05 19:21:57 $ $}} | 44 | \date{{\small \tt\$Date: 1999/05/11 20:46:28 $ $}} |
45 | 45 | ||
46 | \maketitle | 46 | \maketitle |
47 | 47 | ||
@@ -2281,11 +2281,12 @@ except that the table accesses are all raw (that is, without tag methods): | |||
2281 | pos = pos or n | 2281 | pos = pos or n |
2282 | local value = t[pos] | 2282 | local value = t[pos] |
2283 | if n<=0 then return end | 2283 | if n<=0 then return end |
2284 | t.n = n-1 | ||
2285 | while pos < n do | 2284 | while pos < n do |
2286 | t[pos] = t[pos+1] | 2285 | t[pos] = t[pos+1] |
2287 | pos = pos+1 | 2286 | pos = pos+1 |
2288 | end | 2287 | end |
2288 | t[n] = nil | ||
2289 | t.n = n-1 | ||
2289 | return value | 2290 | return value |
2290 | end | 2291 | end |
2291 | \end{verbatim} | 2292 | \end{verbatim} |