lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 1ce819333d3f02d14d983dbddb236e72d4555c7f
parent 88eb901f81d647714d14b6f7e7c6455b46a27daa
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon,  9 Nov 2009 16:54:53 -0200

new option 'isrunning' for 'lua_gc' (and 'collectgarbage')

Diffstat:
Mlapi.c | 6+++++-
Mlbaselib.c | 15++++++++-------
Mlua.h | 3++-
3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lapi.c b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.97 2009/11/06 17:03:37 roberto Exp roberto $ +** $Id: lapi.c,v 2.98 2009/11/09 18:29:21 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -953,6 +953,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { g->gcstepmul = data; break; } + case LUA_GCISRUNNING: { + res = (g->GCthreshold != MAX_LUMEM); + break; + } default: res = -1; /* invalid option */ } lua_unlock(L); diff --git a/lbaselib.c b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.220 2009/10/23 12:50:25 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.221 2009/10/23 19:12:19 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -177,20 +177,21 @@ static int luaB_gcinfo (lua_State *L) { static int luaB_collectgarbage (lua_State *L) { static const char *const opts[] = {"stop", "restart", "collect", - "count", "step", "setpause", "setstepmul", NULL}; + "count", "step", "setpause", "setstepmul", "isrunning", NULL}; static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, - LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; - int o = luaL_checkoption(L, 1, "collect", opts); + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, + LUA_GCISRUNNING}; + int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; int ex = luaL_optint(L, 2, 0); - int res = lua_gc(L, optsnum[o], ex); - switch (optsnum[o]) { + int res = lua_gc(L, o, ex); + switch (o) { case LUA_GCCOUNT: { int b = lua_gc(L, LUA_GCCOUNTB, 0); lua_pushnumber(L, res + ((lua_Number)b/1024)); lua_pushinteger(L, b); return 2; } - case LUA_GCSTEP: { + case LUA_GCSTEP: case LUA_GCISRUNNING: { lua_pushboolean(L, res); return 1; } diff --git a/lua.h b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.247 2009/11/05 16:48:31 roberto Exp roberto $ +** $Id: lua.h,v 1.248 2009/11/05 17:26:00 roberto Exp roberto $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -267,6 +267,7 @@ LUA_API int (lua_status) (lua_State *L); #define LUA_GCSTEP 5 #define LUA_GCSETPAUSE 6 #define LUA_GCSETSTEPMUL 7 +#define LUA_GCISRUNNING 8 LUA_API int (lua_gc) (lua_State *L, int what, int data);