| 171 | |
| 172 | |
| 173 | static int luaB_collectgarbage (lua_State *L) { |
| 174 | static const char *const opts[] = {"stop", "restart", "collect", |
| 175 | "count", "step", "setpause", "setstepmul", |
| 176 | "isrunning", NULL}; |
| 177 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, |
| 178 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, |
| 179 | LUA_GCISRUNNING}; |
| 180 | int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; |
| 181 | int ex = (int)luaL_optinteger(L, 2, 0); |
| 182 | int res = lua_gc(L, o, ex); |
| 183 | switch (o) { |
| 184 | case LUA_GCCOUNT: { |
| 185 | int b = lua_gc(L, LUA_GCCOUNTB, 0); |
| 186 | lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024)); |
| 187 | return 1; |
| 188 | } |
| 189 | case LUA_GCSTEP: case LUA_GCISRUNNING: { |
| 190 | lua_pushboolean(L, res); |
| 191 | return 1; |
| 192 | } |
| 193 | default: { |
| 194 | lua_pushinteger(L, res); |
| 195 | return 1; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | |
| 201 | static int luaB_type (lua_State *L) { |
nothing calls this directly
no test coverage detected