| 1328 | } |
| 1329 | |
| 1330 | int 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 | |
| 1374 | static int dfhack_call_with_finalizer (lua_State *L) |
| 1375 | { |
nothing calls this directly
no test coverage detected