From 816b12cec65e40f8b87b3a90d760ace48ba0d6a3 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 29 Jun 2010 23:14:46 +0000 Subject: [PATCH] Fix selection indexes returned from Auto4 Lua macros to be zero-based instead of one-based. Updates #1219. Originally committed to SVN as r4643. --- aegisub/src/auto4_lua.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 91f6314c9..f77dc4c7e 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -674,7 +674,8 @@ namespace Automation4 { // leave the new table on top of the stack lua_newtable(L); for (size_t i = 0; i != ints.size(); ++i) { - lua_pushinteger(L, ints[i]+1); + // We use zero-based indexing but Lua wants one-based, so add one + lua_pushinteger(L, ints[i] + 1); lua_rawseti(L, -2, (int)i+1); } } @@ -813,7 +814,8 @@ namespace Automation4 { lua_pushnil(L); while (lua_next(L, -2)) { if (lua_isnumber(L, -1)) { - selected.push_back(lua_tointeger(L, -1)); + // Lua uses one-based indexing but we want zero-based, so subtract one + selected.push_back(lua_tointeger(L, -1) - 1); } lua_pop(L, 1); }