forked from mia/Aegisub
Make subs.delete accept a table of rows to delete
Lua has a limit to how many arguments can be pushed onto the stack, so when deleting very large numbers of lines at once unpacking a table can fail.
This commit is contained in:
parent
c685ae4aea
commit
162e119afa
|
@ -448,14 +448,25 @@ namespace Automation4 {
|
||||||
|
|
||||||
// get number of items to delete
|
// get number of items to delete
|
||||||
int itemcount = lua_gettop(L);
|
int itemcount = lua_gettop(L);
|
||||||
std::vector<int> ids;
|
if (itemcount == 0) return;
|
||||||
ids.reserve(itemcount);
|
|
||||||
|
|
||||||
while (itemcount > 0) {
|
std::vector<int> ids;
|
||||||
int n = luaL_checkint(L, itemcount);
|
if (itemcount == 1 && lua_istable(L, 1)) {
|
||||||
luaL_argcheck(L, n > 0 && n <= (int)lines.size(), itemcount, "Out of range line index");
|
lua_pushvalue(L, 1);
|
||||||
ids.push_back(n - 1);
|
lua_for_each(L, [&] {
|
||||||
--itemcount;
|
int n = luaL_checkint(L, -1);
|
||||||
|
luaL_argcheck(L, n > 0 && n <= (int)lines.size(), 1, "Out of range line index");
|
||||||
|
ids.push_back(n - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ids.reserve(itemcount);
|
||||||
|
while (itemcount > 0) {
|
||||||
|
int n = luaL_checkint(L, itemcount);
|
||||||
|
luaL_argcheck(L, n > 0 && n <= (int)lines.size(), itemcount, "Out of range line index");
|
||||||
|
ids.push_back(n - 1);
|
||||||
|
--itemcount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort(ids.begin(), ids.end());
|
sort(ids.begin(), ids.end());
|
||||||
|
|
Loading…
Reference in a new issue