MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / lua_gc

Function lua_gc

third-party/lua-5.3.5/src/lapi.c:1040–1105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1038*/
1039
1040LUA_API int lua_gc (lua_State *L, int what, int data) {
1041 int res = 0;
1042 global_State *g;
1043 lua_lock(L);
1044 g = G(L);
1045 switch (what) {
1046 case LUA_GCSTOP: {
1047 g->gcrunning = 0;
1048 break;
1049 }
1050 case LUA_GCRESTART: {
1051 luaE_setdebt(g, 0);
1052 g->gcrunning = 1;
1053 break;
1054 }
1055 case LUA_GCCOLLECT: {
1056 luaC_fullgc(L, 0);
1057 break;
1058 }
1059 case LUA_GCCOUNT: {
1060 /* GC values are expressed in Kbytes: #bytes/2^10 */
1061 res = cast_int(gettotalbytes(g) >> 10);
1062 break;
1063 }
1064 case LUA_GCCOUNTB: {
1065 res = cast_int(gettotalbytes(g) & 0x3ff);
1066 break;
1067 }
1068 case LUA_GCSTEP: {
1069 l_mem debt = 1; /* =1 to signal that it did an actual step */
1070 lu_byte oldrunning = g->gcrunning;
1071 g->gcrunning = 1; /* allow GC to run */
1072 if (data == 0) {
1073 luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */
1074 luaC_step(L);
1075 }
1076 else { /* add 'data' to total debt */
1077 debt = cast(l_mem, data) * 1024 + g->GCdebt;
1078 luaE_setdebt(g, debt);
1079 luaC_checkGC(L);
1080 }
1081 g->gcrunning = oldrunning; /* restore previous state */
1082 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1083 res = 1; /* signal it */
1084 break;
1085 }
1086 case LUA_GCSETPAUSE: {
1087 res = g->gcpause;
1088 g->gcpause = data;
1089 break;
1090 }
1091 case LUA_GCSETSTEPMUL: {
1092 res = g->gcstepmul;
1093 if (data < 40) data = 40; /* avoid ridiculous low values (and 0) */
1094 g->gcstepmul = data;
1095 break;
1096 }
1097 case LUA_GCISRUNNING: {

Callers 1

luaB_collectgarbageFunction · 0.70

Calls 3

luaE_setdebtFunction · 0.70
luaC_fullgcFunction · 0.70
luaC_stepFunction · 0.70

Tested by

no test coverage detected