MCPcopy Create free account
hub / github.com/DFHack/dfhack / dfhack_cleanup_cont

Function dfhack_cleanup_cont

library/LuaTools.cpp:1330–1372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1328}
1329
1330int dfhack_cleanup_cont(lua_State *L, int status, lua_KContext)
1331{
1332 bool success = Lua::IsSuccess(status);
1333
1334 int nargs = lua_tointeger(L, 1);
1335 bool always = lua_toboolean(L, 2);
1336 int rvbase = 4+nargs;
1337
1338 // stack: [nargs] [always] [errorfun] [cleanup fun] [cleanup args...] |rvbase+1:| [rvals/error...]
1339
1340 int numret = lua_gettop(L) - rvbase;
1341
1342 if (!success || always)
1343 {
1344 if (numret > 0)
1345 {
1346 if (numret == 1)
1347 {
1348 // Inject the only result instead of pulling cleanup args
1349 lua_insert(L, 4);
1350 }
1351 else if (!lua_checkstack(L, nargs+1))
1352 {
1353 success = false;
1354 lua_settop(L, rvbase);
1355 push_simple_error(L, "stack overflow");
1356 lua_insert(L, 4);
1357 }
1358 else
1359 {
1360 for (int i = 0; i <= nargs; i++)
1361 lua_pushvalue(L, 4+i);
1362 }
1363 }
1364
1365 success = do_invoke_cleanup(L, nargs, 3, success);
1366 }
1367
1368 if (!success)
1369 lua_error(L);
1370
1371 return numret;
1372}
1373
1374static int dfhack_call_with_finalizer (lua_State *L)
1375{

Callers

nothing calls this directly

Calls 9

IsSuccessFunction · 0.85
lua_tobooleanFunction · 0.85
lua_gettopFunction · 0.85
lua_checkstackFunction · 0.85
lua_settopFunction · 0.85
push_simple_errorFunction · 0.85
lua_pushvalueFunction · 0.85
do_invoke_cleanupFunction · 0.85
lua_errorFunction · 0.85

Tested by

no test coverage detected