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 | |
| parent | 88eb901f81d647714d14b6f7e7c6455b46a27daa (diff) | |
| download | lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.tar.gz lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.tar.bz2 lua-1ce819333d3f02d14d983dbddb236e72d4555c7f.zip | |
new option 'isrunning' for 'lua_gc' (and 'collectgarbage')
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | lbaselib.c | 15 | ||||
| -rw-r--r-- | lua.h | 3 |
3 files changed, 15 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.97 2009/11/06 17:03:37 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.98 2009/11/09 18:29:21 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 | */ |
| @@ -953,6 +953,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 953 | g->gcstepmul = data; | 953 | g->gcstepmul = data; |
| 954 | break; | 954 | break; |
| 955 | } | 955 | } |
| 956 | case LUA_GCISRUNNING: { | ||
| 957 | res = (g->GCthreshold != MAX_LUMEM); | ||
| 958 | break; | ||
| 959 | } | ||
| 956 | default: res = -1; /* invalid option */ | 960 | default: res = -1; /* invalid option */ |
| 957 | } | 961 | } |
| 958 | lua_unlock(L); | 962 | lua_unlock(L); |
| @@ -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 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.247 2009/11/05 16:48:31 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.248 2009/11/05 17:26:00 roberto Exp roberto $ |
| 3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -267,6 +267,7 @@ LUA_API int (lua_status) (lua_State *L); | |||
| 267 | #define LUA_GCSTEP 5 | 267 | #define LUA_GCSTEP 5 |
| 268 | #define LUA_GCSETPAUSE 6 | 268 | #define LUA_GCSETPAUSE 6 |
| 269 | #define LUA_GCSETSTEPMUL 7 | 269 | #define LUA_GCSETSTEPMUL 7 |
| 270 | #define LUA_GCISRUNNING 8 | ||
| 270 | 271 | ||
| 271 | LUA_API int (lua_gc) (lua_State *L, int what, int data); | 272 | LUA_API int (lua_gc) (lua_State *L, int what, int data); |
| 272 | 273 | ||
