MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / lua_gc

Function lua_gc

src/Chain/libraries/glua/lapi.cpp:1127–1192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaB_collectgarbageFunction · 0.85

Calls 3

luaE_setdebtFunction · 0.85
luaC_fullgcFunction · 0.85
luaC_stepFunction · 0.85

Tested by

no test coverage detected