diff options
| author | navewindre <boneyaard@gmail.com> | 2025-04-05 02:59:37 +0200 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2025-04-05 02:59:37 +0200 |
| commit | b24463f3d045783b8f4e72926054d53b908e150f (patch) | |
| tree | 036f976e217128b9e4acf3854f72908c27dec17b /config/mpv/scripts/subs2srsa/utils/switch.lua | |
| parent | 398e41be4daf339bd55862520c528a7d93b83fb6 (diff) | |
a
Diffstat (limited to 'config/mpv/scripts/subs2srsa/utils/switch.lua')
| -rw-r--r-- | config/mpv/scripts/subs2srsa/utils/switch.lua | 38 |
1 files changed, 38 insertions, 0 deletions
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 +} |
