commit 345379b5ff7ce6f5a732a6954bfb5e83bce12036
parent 118e471fa0fd9db1c3a4b966a4312f65d4aa33a7
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 4 Jun 2004 12:30:31 -0300
option for garbage-collector `step'
Diffstat:
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.9 2004/05/14 19:25:09 roberto Exp roberto $
+** $Id: lapi.c,v 2.10 2004/05/31 19:41:52 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -833,6 +833,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
/* GC values are expressed in Kbytes: #bytes/2^10 */
return cast(int, g->nblocks >> 10);
}
+ case LUA_GCSTEP: {
+ lu_mem a = (cast(lu_mem, data) << 10);
+ if (a <= g->nblocks)
+ g->GCthreshold = g->nblocks - a;
+ else
+ g->GCthreshold = 0;
+ luaC_step(L);
+ return 0;
+ }
default: return -1; /* invalid option */
}
}
diff --git a/lbaselib.c b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.144 2004/05/31 18:50:30 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.145 2004/06/02 14:20:08 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -180,22 +180,11 @@ static int luaB_gcinfo (lua_State *L) {
static int luaB_collectgarbage (lua_State *L) {
static const char *const opts[] = {"stop", "restart", "collect", "count",
- NULL};
+ "step", NULL};
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART,
- LUA_GCCOLLECT, LUA_GCCOUNT};
- int o;
- int ex;
-#if 1
- if (lua_isnumber(L, 1)) {
- int v = lua_tointeger(L, 1);
- lua_settop(L, 0);
- if (v == 0) lua_pushstring(L, "collect");
- else if (v >= 10000) lua_pushstring(L, "stop");
- else lua_pushstring(L, "restart");
- }
-#endif
- o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
- ex = luaL_optint(L, 2, 0);
+ LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCSTEP};
+ int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
+ int ex = luaL_optint(L, 2, 0);
luaL_argcheck(L, o >= 0, 1, "invalid option");
lua_pushinteger(L, lua_gc(L, optsnum[o], ex));
return 1;
diff --git a/lua.h b/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.190 2004/05/31 19:41:52 roberto Exp roberto $
+** $Id: lua.h,v 1.191 2004/06/02 17:37:03 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -217,6 +217,7 @@ LUA_API int lua_resume (lua_State *L, int narg);
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
+#define LUA_GCSTEP 4
LUA_API int lua_gc (lua_State *L, int what, int data);