MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / lua_gc

Function lua_gc

Source/Misc/lua/src/lua.c:2748–2804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2746*/
2747
2748LUA_API int lua_gc (lua_State *L, int what, int data) {
2749int res = 0;
2750global_State *g;
2751lua_lock(L);
2752g = G(L);
2753switch (what) {
2754case LUA_GCSTOP: {
2755g->GCthreshold = MAX_LUMEM;
2756break;
2757}
2758case LUA_GCRESTART: {
2759g->GCthreshold = g->totalbytes;
2760break;
2761}
2762case LUA_GCCOLLECT: {
2763luaC_fullgc(L);
2764break;
2765}
2766case LUA_GCCOUNT: {
2767/* GC values are expressed in Kbytes: #bytes/2^10 */
2768res = cast_int(g->totalbytes >> 10);
2769break;
2770}
2771case LUA_GCCOUNTB: {
2772res = cast_int(g->totalbytes & 0x3ff);
2773break;
2774}
2775case LUA_GCSTEP: {
2776lu_mem a = (cast(lu_mem, data) << 10);
2777if (a <= g->totalbytes)
2778g->GCthreshold = g->totalbytes - a;
2779else
2780g->GCthreshold = 0;
2781while (g->GCthreshold <= g->totalbytes) {
2782luaC_step(L);
2783if (g->gcstate == GCSpause) { /* end of cycle? */
2784res = 1; /* signal it */
2785break;
2786}
2787}
2788break;
2789}
2790case LUA_GCSETPAUSE: {
2791res = g->gcpause;
2792g->gcpause = data;
2793break;
2794}
2795case LUA_GCSETSTEPMUL: {
2796res = g->gcstepmul;
2797g->gcstepmul = data;
2798break;
2799}
2800default: res = -1; /* invalid option */
2801}
2802lua_unlock(L);
2803return res;
2804}
2805

Callers 1

luaB_collectgarbageFunction · 0.85

Calls 2

luaC_fullgcFunction · 0.85
luaC_stepFunction · 0.85

Tested by

no test coverage detected