From 162e119afa525ae156556d95156f98089691fe95 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 15 Apr 2014 20:47:59 -0700 Subject: [PATCH] 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. --- src/auto4_lua_assfile.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 615e4b5a3..b21bbcfdf 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -448,14 +448,25 @@ namespace Automation4 { // get number of items to delete int itemcount = lua_gettop(L); - std::vector ids; - ids.reserve(itemcount); + if (itemcount == 0) return; - 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; + std::vector ids; + if (itemcount == 1 && lua_istable(L, 1)) { + lua_pushvalue(L, 1); + lua_for_each(L, [&] { + 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());