MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / lua_gc

Function lua_gc

lib/lua/src/lapi.c:1133–1229  ·  view source on GitHub ↗

** Garbage-collection function */

Source from the content-addressed store, hash-verified

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

Callers 5

pmainFunction · 0.85
mainFunction · 0.85
luaB_collectgarbageFunction · 0.85
collectGarbageMethod · 0.85

Calls 5

luaE_setdebtFunction · 0.85
luaC_fullgcFunction · 0.85
luaC_stepFunction · 0.85
luaC_changemodeFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected