diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-09 16:55:17 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-09 16:55:17 -0200 |
commit | 1ce819333d3f02d14d983dbddb236e72d4555c7f (patch) | |
tree | d77bbff87e140161cb6b0e6d423da1123de10e88 /lbaselib.c | |
parent | 88eb901f81d647714d14b6f7e7c6455b46a27daa (diff) | |
download | lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.tar.gz lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.tar.bz2 lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.zip |
new option 'isrunning' for 'lua_gc' (and 'collectgarbage')
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.220 2009/10/23 12:50:25 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.221 2009/10/23 19:12:19 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 | */ |
@@ -177,20 +177,21 @@ static int luaB_gcinfo (lua_State *L) { | |||
177 | 177 | ||
178 | static int luaB_collectgarbage (lua_State *L) { | 178 | static int luaB_collectgarbage (lua_State *L) { |
179 | static const char *const opts[] = {"stop", "restart", "collect", | 179 | static const char *const opts[] = {"stop", "restart", "collect", |
180 | "count", "step", "setpause", "setstepmul", NULL}; | 180 | "count", "step", "setpause", "setstepmul", "isrunning", NULL}; |
181 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, | 181 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, |
182 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; | 182 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, |
183 | int o = luaL_checkoption(L, 1, "collect", opts); | 183 | LUA_GCISRUNNING}; |
184 | int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; | ||
184 | int ex = luaL_optint(L, 2, 0); | 185 | int ex = luaL_optint(L, 2, 0); |
185 | int res = lua_gc(L, optsnum[o], ex); | 186 | int res = lua_gc(L, o, ex); |
186 | switch (optsnum[o]) { | 187 | switch (o) { |
187 | case LUA_GCCOUNT: { | 188 | case LUA_GCCOUNT: { |
188 | int b = lua_gc(L, LUA_GCCOUNTB, 0); | 189 | int b = lua_gc(L, LUA_GCCOUNTB, 0); |
189 | lua_pushnumber(L, res + ((lua_Number)b/1024)); | 190 | lua_pushnumber(L, res + ((lua_Number)b/1024)); |
190 | lua_pushinteger(L, b); | 191 | lua_pushinteger(L, b); |
191 | return 2; | 192 | return 2; |
192 | } | 193 | } |
193 | case LUA_GCSTEP: { | 194 | case LUA_GCSTEP: case LUA_GCISRUNNING: { |
194 | lua_pushboolean(L, res); | 195 | lua_pushboolean(L, res); |
195 | return 1; | 196 | return 1; |
196 | } | 197 | } |