mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
tremove erases its previous last element (to avoid locking potential
garbagge).
This commit is contained in:
parent
3b533ea7c7
commit
5caf7f4a33
15
lbuiltin.c
15
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<n; pos++)
|
||||
luaH_move(a, pos+1, pos);
|
||||
luaH_move(a, pos+1, pos); /* a[pos] = a[pos+1] */
|
||||
luaV_setn(a, n-1); /* a.n = n-1 */
|
||||
luaH_setint(a, n, &luaO_nilobject); /* a[n] = nil */
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
% $Id: manual.tex,v 1.31 1999/05/05 19:21:57 roberto Exp roberto $
|
||||
% $Id: manual.tex,v 1.32 1999/05/11 20:46:28 roberto Exp roberto $
|
||||
|
||||
\documentclass[11pt]{article}
|
||||
\usepackage{fullpage,bnf}
|
||||
@ -41,7 +41,7 @@ Waldemar Celes
|
||||
\tecgraf\ --- Computer Science Department --- PUC-Rio
|
||||
}
|
||||
|
||||
\date{{\small \tt\$Date: 1999/05/05 19:21:57 $ $}}
|
||||
\date{{\small \tt\$Date: 1999/05/11 20:46:28 $ $}}
|
||||
|
||||
\maketitle
|
||||
|
||||
@ -2281,11 +2281,12 @@ except that the table accesses are all raw (that is, without tag methods):
|
||||
pos = pos or n
|
||||
local value = t[pos]
|
||||
if n<=0 then return end
|
||||
t.n = n-1
|
||||
while pos < n do
|
||||
t[pos] = t[pos+1]
|
||||
pos = pos+1
|
||||
end
|
||||
t[n] = nil
|
||||
t.n = n-1
|
||||
return value
|
||||
end
|
||||
\end{verbatim}
|
||||
|
Loading…
x
Reference in New Issue
Block a user