Add collectgarbage("isrunning").

This commit is contained in:
Mike Pall 2015-10-01 16:26:00 +02:00
parent 0b09c971c9
commit 86c21bd245
3 changed files with 6 additions and 2 deletions

View File

@ -435,13 +435,13 @@ LJLIB_CF(gcinfo)
LJLIB_CF(collectgarbage) LJLIB_CF(collectgarbage)
{ {
int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */ int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */
"\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul"); "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul\1\377\11isrunning");
int32_t data = lj_lib_optint(L, 2, 0); int32_t data = lj_lib_optint(L, 2, 0);
if (opt == LUA_GCCOUNT) { if (opt == LUA_GCCOUNT) {
setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0); setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);
} else { } else {
int res = lua_gc(L, opt, data); int res = lua_gc(L, opt, data);
if (opt == LUA_GCSTEP) if (opt == LUA_GCSTEP || opt == LUA_GCISRUNNING)
setboolV(L->top, res); setboolV(L->top, res);
else else
setintV(L->top, res); setintV(L->top, res);

View File

@ -1188,6 +1188,9 @@ LUA_API int lua_gc(lua_State *L, int what, int data)
res = (int)(g->gc.stepmul); res = (int)(g->gc.stepmul);
g->gc.stepmul = (MSize)data; g->gc.stepmul = (MSize)data;
break; break;
case LUA_GCISRUNNING:
res = (g->gc.threshold != LJ_MAX_MEM);
break;
default: default:
res = -1; /* Invalid option. */ res = -1; /* Invalid option. */
} }

View File

@ -226,6 +226,7 @@ LUA_API int (lua_status) (lua_State *L);
#define LUA_GCSTEP 5 #define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6 #define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7 #define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
LUA_API int (lua_gc) (lua_State *L, int what, int data); LUA_API int (lua_gc) (lua_State *L, int what, int data);