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

Function luaB_collectgarbage

lib/lua/src/lbaselib.c:199–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197#define checkvalres(res) { if (res == -1) break; }
198
199static int luaB_collectgarbage (lua_State *L) {
200 static const char *const opts[] = {"stop", "restart", "collect",
201 "count", "step", "setpause", "setstepmul",
202 "isrunning", "generational", "incremental", NULL};
203 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
204 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
205 LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
206 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
207 switch (o) {
208 case LUA_GCCOUNT: {
209 int k = lua_gc(L, o);
210 int b = lua_gc(L, LUA_GCCOUNTB);
211 checkvalres(k);
212 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024));
213 return 1;
214 }
215 case LUA_GCSTEP: {
216 int step = (int)luaL_optinteger(L, 2, 0);
217 int res = lua_gc(L, o, step);
218 checkvalres(res);
219 lua_pushboolean(L, res);
220 return 1;
221 }
222 case LUA_GCSETPAUSE:
223 case LUA_GCSETSTEPMUL: {
224 int p = (int)luaL_optinteger(L, 2, 0);
225 int previous = lua_gc(L, o, p);
226 checkvalres(previous);
227 lua_pushinteger(L, previous);
228 return 1;
229 }
230 case LUA_GCISRUNNING: {
231 int res = lua_gc(L, o);
232 checkvalres(res);
233 lua_pushboolean(L, res);
234 return 1;
235 }
236 case LUA_GCGEN: {
237 int minormul = (int)luaL_optinteger(L, 2, 0);
238 int majormul = (int)luaL_optinteger(L, 3, 0);
239 return pushmode(L, lua_gc(L, o, minormul, majormul));
240 }
241 case LUA_GCINC: {
242 int pause = (int)luaL_optinteger(L, 2, 0);
243 int stepmul = (int)luaL_optinteger(L, 3, 0);
244 int stepsize = (int)luaL_optinteger(L, 4, 0);
245 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
246 }
247 default: {
248 int res = lua_gc(L, o);
249 checkvalres(res);
250 lua_pushinteger(L, res);
251 return 1;
252 }
253 }
254 luaL_pushfail(L); /* invalid call (inside a finalizer) */
255 return 1;
256}

Callers

nothing calls this directly

Calls 7

luaL_checkoptionFunction · 0.85
lua_gcFunction · 0.85
lua_pushnumberFunction · 0.85
luaL_optintegerFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushintegerFunction · 0.85
pushmodeFunction · 0.85

Tested by

no test coverage detected