瀏覽代碼

more precision for gc count

Roberto Ierusalimschy 20 年之前
父節點
當前提交
9f4211310f
共有 3 個文件被更改,包括 28 次插入9 次删除
  1. 5 1
      lapi.c
  2. 18 4
      lbaselib.c
  3. 5 4
      lua.h

+ 5 - 1
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.49 2005/09/14 17:44:48 roberto Exp roberto $
+** $Id: lapi.c,v 2.50 2005/09/20 17:55:10 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -913,6 +913,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
       res = cast(int, g->totalbytes >> 10);
       break;
     }
+    case LUA_GCCOUNTB: {
+      res = cast(int, g->totalbytes & 0x3ff);
+      break;
+    }
     case LUA_GCSTEP: {
       lu_mem a = (cast(lu_mem, data) << 10);
       if (a <= g->totalbytes)

+ 18 - 4
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbaselib.c,v 1.183 2005/09/16 18:22:48 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.184 2005/10/03 14:36:45 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -196,9 +196,23 @@ static int luaB_collectgarbage (lua_State *L) {
   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);
-  int ex = luaL_optinteger(L, 2, 0);
-  lua_pushinteger(L, lua_gc(L, optsnum[o], ex));
-  return 1;
+  int ex = luaL_optint(L, 2, 0);
+  int res = lua_gc(L, optsnum[o], ex);
+  switch (optsnum[o]) {
+    case LUA_GCCOUNT: {
+      int b = lua_gc(L, LUA_GCCOUNTB, 0);
+      lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
+      return 1;
+    }
+    case LUA_GCSTEP: {
+      lua_pushboolean(L, res);
+      return 1;
+    }
+    default: {
+      lua_pushnumber(L, res);
+      return 1;
+    }
+  }
 }
 
 

+ 5 - 4
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp roberto $
+** $Id: lua.h,v 1.213 2005/09/20 17:55:10 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
 ** See Copyright Notice at the end of this file
@@ -221,9 +221,10 @@ LUA_API int  (lua_status) (lua_State *L);
 #define LUA_GCRESTART		1
 #define LUA_GCCOLLECT		2
 #define LUA_GCCOUNT		3
-#define LUA_GCSTEP		4
-#define LUA_GCSETPAUSE		5
-#define LUA_GCSETSTEPMUL	6
+#define LUA_GCCOUNTB		4
+#define LUA_GCSTEP		5
+#define LUA_GCSETPAUSE		6
+#define LUA_GCSETSTEPMUL	7
 
 LUA_API int (lua_gc) (lua_State *L, int what, int data);