From d6c4365b8de32b621ac46074a9b69908b95686c0 Mon Sep 17 00:00:00 2001 From: navewindre Date: Sat, 5 Apr 2025 03:00:29 +0200 Subject: a --- config/mpv/scripts/subs2srs/utils/switch.lua | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 config/mpv/scripts/subs2srs/utils/switch.lua (limited to 'config/mpv/scripts/subs2srs/utils/switch.lua') diff --git a/config/mpv/scripts/subs2srs/utils/switch.lua b/config/mpv/scripts/subs2srs/utils/switch.lua new file mode 100644 index 0000000..5dac1c6 --- /dev/null +++ b/config/mpv/scripts/subs2srs/utils/switch.lua @@ -0,0 +1,38 @@ +--[[ +Copyright: Ren Tatsumoto and contributors +License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/gpl.html + +Switch cycles between values in a table. +]] + +local make_switch = function(states) + local self = { + states = states, + current_state = 1 + } + local bump = function() + self.current_state = self.current_state + 1 + if self.current_state > #self.states then + self.current_state = 1 + end + end + local get = function() + return self.states[self.current_state] + end + local set = function(new_state) + for idx, value in ipairs(self.states) do + if value == new_state then + self.current_state = idx + end + end + end + return { + bump = bump, + get = get, + set = set, + } +end + +return { + new = make_switch +} -- cgit v1.2.3