diff --git a/src/uosc/elements/CycleButton.lua b/src/uosc/elements/CycleButton.lua index 60598494..61cd666c 100644 --- a/src/uosc/elements/CycleButton.lua +++ b/src/uosc/elements/CycleButton.lua @@ -52,7 +52,7 @@ function CycleButton:init(id, props) self['on_prop_' .. self.prop] = function(self, value) handle_change(self.prop, value) end handle_change(self.prop, state[self.prop]) else - self:observe_mp_property(self.prop, handle_change) + self:observe_mp_property(self.prop, 'string', handle_change) end end diff --git a/src/uosc/elements/Element.lua b/src/uosc/elements/Element.lua index 3e3f4584..733d63ee 100644 --- a/src/uosc/elements/Element.lua +++ b/src/uosc/elements/Element.lua @@ -182,9 +182,12 @@ end -- Automatically registers disposer for the observer. ---@param name string ----@param callback fun(name: string, value: any) -function Element:observe_mp_property(name, callback) - mp.observe_property(name, 'native', callback) +---@param type_or_callback string|fun(name: string, value: any) +---@param callback_maybe nil|fun(name: string, value: any) +function Element:observe_mp_property(name, type_or_callback, callback_maybe) + local callback = type(type_or_callback) == 'function' and type_or_callback or callback_maybe + local prop_type = type(type_or_callback) == 'string' and type_or_callback or 'native' + mp.observe_property(name, prop_type, callback) self:register_disposer(function() mp.unobserve_property(callback) end) end