| 1441 | } |
| 1442 | |
| 1443 | static int dfhack_curry_wrap(lua_State *L) |
| 1444 | { |
| 1445 | int nargs = lua_gettop(L); |
| 1446 | int ncurry = lua_tointeger(L, lua_upvalueindex(1)); |
| 1447 | int scount = nargs + ncurry; |
| 1448 | |
| 1449 | luaL_checkstack(L, ncurry, "stack overflow in curry"); |
| 1450 | |
| 1451 | // Insert values in O(N+M) by first shifting the existing data |
| 1452 | lua_settop(L, scount); |
| 1453 | for (int i = 0; i < nargs; i++) |
| 1454 | lua_copy(L, nargs-i, scount-i); |
| 1455 | for (int i = 1; i <= ncurry; i++) |
| 1456 | lua_copy(L, lua_upvalueindex(i+1), i); |
| 1457 | |
| 1458 | lua_callk(L, scount-1, LUA_MULTRET, 0, gettop_wrapper); |
| 1459 | |
| 1460 | return lua_gettop(L); |
| 1461 | } |
| 1462 | |
| 1463 | static int dfhack_curry(lua_State *L) |
| 1464 | { |
nothing calls this directly
no test coverage detected