MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / lua_gc

Function lua_gc

lua/src/lapi.c:1136–1232  ·  view source on GitHub ↗

** Garbage-collection function */

Source from the content-addressed store, hash-verified

1134** Garbage-collection function
1135*/
1136LUA_API int lua_gc (lua_State *L, int what, ...) {
1137 va_list argp;
1138 int res = 0;
1139 global_State *g = G(L);
1140 if (g->gcstp & GCSTPGC) /* internal stop? */
1141 return -1; /* all options are invalid when stopped */
1142 lua_lock(L);
1143 va_start(argp, what);
1144 switch (what) {
1145 case LUA_GCSTOP: {
1146 g->gcstp = GCSTPUSR; /* stopped by the user */
1147 break;
1148 }
1149 case LUA_GCRESTART: {
1150 luaE_setdebt(g, 0);
1151 g->gcstp = 0; /* (GCSTPGC must be already zero here) */
1152 break;
1153 }
1154 case LUA_GCCOLLECT: {
1155 luaC_fullgc(L, 0);
1156 break;
1157 }
1158 case LUA_GCCOUNT: {
1159 /* GC values are expressed in Kbytes: #bytes/2^10 */
1160 res = cast_int(gettotalbytes(g) >> 10);
1161 break;
1162 }
1163 case LUA_GCCOUNTB: {
1164 res = cast_int(gettotalbytes(g) & 0x3ff);
1165 break;
1166 }
1167 case LUA_GCSTEP: {
1168 int data = va_arg(argp, int);
1169 l_mem debt = 1; /* =1 to signal that it did an actual step */
1170 lu_byte oldstp = g->gcstp;
1171 g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */
1172 if (data == 0) {
1173 luaE_setdebt(g, 0); /* do a basic step */
1174 luaC_step(L);
1175 }
1176 else { /* add 'data' to total debt */
1177 debt = cast(l_mem, data) * 1024 + g->GCdebt;
1178 luaE_setdebt(g, debt);
1179 luaC_checkGC(L);
1180 }
1181 g->gcstp = oldstp; /* restore previous state */
1182 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1183 res = 1; /* signal it */
1184 break;
1185 }
1186 case LUA_GCSETPAUSE: {
1187 int data = va_arg(argp, int);
1188 res = getgcparam(g->gcpause);
1189 setgcparam(g->gcpause, data);
1190 break;
1191 }
1192 case LUA_GCSETSTEPMUL: {
1193 int data = va_arg(argp, int);

Callers 2

pmainFunction · 0.85
luaB_collectgarbageFunction · 0.85

Calls 4

luaE_setdebtFunction · 0.85
luaC_fullgcFunction · 0.85
luaC_stepFunction · 0.85
luaC_changemodeFunction · 0.85

Tested by

no test coverage detected