MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / lua_gc

Function lua_gc

3rd/lua-5.4.3/src/lapi.c:1126–1221  ·  view source on GitHub ↗

** Garbage-collection function */

Source from the content-addressed store, hash-verified

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

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