mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: aaf00c908ca37b1c61419049d3128083e47dc9fc
Parent: eb4475ff9c655a3840e65dcb14ac5867f7c9e790
Author: Ren Tatsumoto
Date:   Thu, 22 Oct 2020 19:58:49 +0300

replace math.max with table.max

There is a limit for a number of arguments in Lua.
math.max() crashes the add-on when note_ids contain more than 999964 elements.

Diffstat:
Msubs2srs.lua | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -83,6 +83,16 @@ function table.contains(table, element) return false end +function table.max(table) + local max = table[1] + for _, value in ipairs(table) do + if value > max then + max = value + end + end + return max +end + local function is_empty(var) return var == nil or var == '' or (type(var) == 'table' and next(var) == nil) end @@ -558,8 +568,7 @@ ankiconnect.get_last_note_id = function() local note_ids, _ = ankiconnect.parse_result(ret) if not is_empty(note_ids) then - local last_note_id = math.max(table.unpack(note_ids)) - return last_note_id + return table.max(note_ids) else return -1 end