From b24463f3d045783b8f4e72926054d53b908e150f Mon Sep 17 00:00:00 2001 From: navewindre Date: Sat, 5 Apr 2025 02:59:37 +0200 Subject: a --- config/mpv/scripts/subs2srsa/utils/switch.lua | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 config/mpv/scripts/subs2srsa/utils/switch.lua (limited to 'config/mpv/scripts/subs2srsa/utils/switch.lua') diff --git a/config/mpv/scripts/subs2srsa/utils/switch.lua b/config/mpv/scripts/subs2srsa/utils/switch.lua new file mode 100644 index 0000000..5dac1c6 --- /dev/null +++ b/config/mpv/scripts/subs2srsa/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