tremove erases its previous last element (to avoid locking potential
garbagge).
This commit is contained in:
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
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -470,10 +470,10 @@ static void luaB_tinsert (void) {
|
|||||||
v = luaL_nonnullarg(2);
|
v = luaL_nonnullarg(2);
|
||||||
pos = n+1;
|
pos = n+1;
|
||||||
}
|
}
|
||||||
luaV_setn(a, n+1); /* increment field "n" */
|
luaV_setn(a, n+1); /* a.n = n+1 */
|
||||||
for ( ;n>=pos; n--)
|
for ( ;n>=pos; n--)
|
||||||
luaH_move(a, n, n+1);
|
luaH_move(a, n, n+1); /* a[n+1] = a[n] */
|
||||||
luaH_setint(a, pos, luaA_Address(v));
|
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 n = (int)getnarg(a);
|
||||||
int pos = luaL_opt_int(2, n);
|
int pos = luaL_opt_int(2, n);
|
||||||
if (n <= 0) return; /* table is "empty" */
|
if (n <= 0) return; /* table is "empty" */
|
||||||
luaA_pushobject(luaH_getint(a, pos)); /* push result */
|
luaA_pushobject(luaH_getint(a, pos)); /* result = a[pos] */
|
||||||
luaV_setn(a, n-1); /* decrement field "n" */
|
|
||||||
for ( ;pos<n; 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}
|
\documentclass[11pt]{article}
|
||||||
\usepackage{fullpage,bnf}
|
\usepackage{fullpage,bnf}
|
||||||
@@ -41,7 +41,7 @@ Waldemar Celes
|
|||||||
\tecgraf\ --- Computer Science Department --- PUC-Rio
|
\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
|
\maketitle
|
||||||
|
|
||||||
@@ -2281,11 +2281,12 @@ except that the table accesses are all raw (that is, without tag methods):
|
|||||||
pos = pos or n
|
pos = pos or n
|
||||||
local value = t[pos]
|
local value = t[pos]
|
||||||
if n<=0 then return end
|
if n<=0 then return end
|
||||||
t.n = n-1
|
|
||||||
while pos < n do
|
while pos < n do
|
||||||
t[pos] = t[pos+1]
|
t[pos] = t[pos+1]
|
||||||
pos = pos+1
|
pos = pos+1
|
||||||
end
|
end
|
||||||
|
t[n] = nil
|
||||||
|
t.n = n-1
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|||||||
Reference in New Issue
Block a user