Explorar el Código

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

Roberto Ierusalimschy hace 15 años
padre
commit
1ce819333d
Se han modificado 3 ficheros con 15 adiciones y 9 borrados
  1. 5 1
      lapi.c
  2. 8 7
      lbaselib.c
  3. 2 1
      lua.h

+ 5 - 1
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);

+ 8 - 7
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;
     }

+ 2 - 1
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);