summaryrefslogtreecommitdiffstats
path: root/DOCS/man/lua.rst
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2024-01-14 08:00:08 +0100
committerDudemanguy <random342@airmail.cc>2024-01-20 16:09:34 +0000
commitde0849404b65876f0f8fe934c4b74f497bf4e29b (patch)
treed1d8d91b08efa1d88e8b5697f5e8b088012a0404 /DOCS/man/lua.rst
parentc209d4f73bc69778a31cf1db975379be91a7f26b (diff)
downloadmpv-de0849404b65876f0f8fe934c4b74f497bf4e29b.tar.bz2
mpv-de0849404b65876f0f8fe934c4b74f497bf4e29b.tar.xz
scripting: don't observe properties with type nil
mp.observe_property('foo', nil, ...) calls the handler at least 2 times on each playlist change even when the property doesn't change. This is dangerous because if you haven't read observe_property's documentation in a long time this is easy to forget, and you can end up using it for handlers that are computationally expensive or that cause unintended side effects. Therefore, this commit discourages its use more explicitly in the documentation, and replaces its usages in scripts. For console.lua, observing focused with type nil leads to calling mp.osd_message('') when changing file while playing in the terminal with the console disabled. I don't notice issues from this, but it's safer to avoid it. For playlist and track-list this doesn't really matter since they trigger multiple changes on each new file anyway, but changing it can avoid encouraging people to imitate the code. One usage of none in stats.lua is kept because according to b9084dfd47 it is a hack to replicate the deprecated tick event.
Diffstat (limited to 'DOCS/man/lua.rst')
-rw-r--r--DOCS/man/lua.rst6
1 files changed, 3 insertions, 3 deletions
diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst
index 1ea612a0be..6a18e60e1d 100644
--- a/DOCS/man/lua.rst
+++ b/DOCS/man/lua.rst
@@ -426,9 +426,9 @@ The ``mp`` module is preloaded, although it can be loaded manually with
This depends on the property, and it's a valid feature request to ask for
better update handling of a specific property.
- If the ``type`` is ``none`` or ``nil``, sporadic property change events are
- possible. This means the change function ``fn`` can be called even if the
- property doesn't actually change.
+ If the ``type`` is ``none`` or ``nil``, the change function ``fn`` will be
+ called sporadically even if the property doesn't actually change. You should
+ therefore avoid using these types.
You always get an initial change notification. This is meant to initialize
the user's state to the current value of the property.