diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-04 12:30:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-04 12:30:53 -0300 |
commit | 345379b5ff7ce6f5a732a6954bfb5e83bce12036 (patch) | |
tree | 2d55667999fe8e4d5986ab8cc13eaeb837657642 | |
parent | 118e471fa0fd9db1c3a4b966a4312f65d4aa33a7 (diff) | |
download | lua-345379b5ff7ce6f5a732a6954bfb5e83bce12036.tar.gz lua-345379b5ff7ce6f5a732a6954bfb5e83bce12036.tar.bz2 lua-345379b5ff7ce6f5a732a6954bfb5e83bce12036.zip |
option for garbage-collector `step'
-rw-r--r-- | lapi.c | 11 | ||||
-rw-r--r-- | lbaselib.c | 21 | ||||
-rw-r--r-- | lua.h | 3 |
3 files changed, 17 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.9 2004/05/14 19:25:09 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.10 2004/05/31 19:41:52 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -833,6 +833,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
833 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 833 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
834 | return cast(int, g->nblocks >> 10); | 834 | return cast(int, g->nblocks >> 10); |
835 | } | 835 | } |
836 | case LUA_GCSTEP: { | ||
837 | lu_mem a = (cast(lu_mem, data) << 10); | ||
838 | if (a <= g->nblocks) | ||
839 | g->GCthreshold = g->nblocks - a; | ||
840 | else | ||
841 | g->GCthreshold = 0; | ||
842 | luaC_step(L); | ||
843 | return 0; | ||
844 | } | ||
836 | default: return -1; /* invalid option */ | 845 | default: return -1; /* invalid option */ |
837 | } | 846 | } |
838 | } | 847 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.144 2004/05/31 18:50:30 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.145 2004/06/02 14:20:08 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -180,22 +180,11 @@ static int luaB_gcinfo (lua_State *L) { | |||
180 | 180 | ||
181 | static int luaB_collectgarbage (lua_State *L) { | 181 | static int luaB_collectgarbage (lua_State *L) { |
182 | static const char *const opts[] = {"stop", "restart", "collect", "count", | 182 | static const char *const opts[] = {"stop", "restart", "collect", "count", |
183 | NULL}; | 183 | "step", NULL}; |
184 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, | 184 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, |
185 | LUA_GCCOLLECT, LUA_GCCOUNT}; | 185 | LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCSTEP}; |
186 | int o; | 186 | int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); |
187 | int ex; | 187 | int ex = luaL_optint(L, 2, 0); |
188 | #if 1 | ||
189 | if (lua_isnumber(L, 1)) { | ||
190 | int v = lua_tointeger(L, 1); | ||
191 | lua_settop(L, 0); | ||
192 | if (v == 0) lua_pushstring(L, "collect"); | ||
193 | else if (v >= 10000) lua_pushstring(L, "stop"); | ||
194 | else lua_pushstring(L, "restart"); | ||
195 | } | ||
196 | #endif | ||
197 | o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); | ||
198 | ex = luaL_optint(L, 2, 0); | ||
199 | luaL_argcheck(L, o >= 0, 1, "invalid option"); | 188 | luaL_argcheck(L, o >= 0, 1, "invalid option"); |
200 | lua_pushinteger(L, lua_gc(L, optsnum[o], ex)); | 189 | lua_pushinteger(L, lua_gc(L, optsnum[o], ex)); |
201 | return 1; | 190 | return 1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.190 2004/05/31 19:41:52 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.191 2004/06/02 17:37:03 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
5 | ** http://www.lua.org mailto:info@lua.org | 5 | ** http://www.lua.org mailto:info@lua.org |
@@ -217,6 +217,7 @@ LUA_API int lua_resume (lua_State *L, int narg); | |||
217 | #define LUA_GCRESTART 1 | 217 | #define LUA_GCRESTART 1 |
218 | #define LUA_GCCOLLECT 2 | 218 | #define LUA_GCCOLLECT 2 |
219 | #define LUA_GCCOUNT 3 | 219 | #define LUA_GCCOUNT 3 |
220 | #define LUA_GCSTEP 4 | ||
220 | 221 | ||
221 | LUA_API int lua_gc (lua_State *L, int what, int data); | 222 | LUA_API int lua_gc (lua_State *L, int what, int data); |
222 | 223 | ||