summaryrefslogtreecommitdiffstats
path: root/player/lua/defaults.lua
Commit message (Collapse)AuthorAgeFilesLines
* player: remove shared-script-properties propertyDudemanguy2023-11-221-24/+0
| | | | | | | | | | | | This property was never encouraged. The manual even stated that "You should avoid using it, unless you absolutely have to." Since we now have user-data which is superior in every single way and replaces this, delete this property. The manual also has threatened people for years with the line "It's a makeshift solution which could go away any time (for example, when a better solution becomes available)." We were nice and deprecated it in 1d00aee8e191c9689a20e67e3d6dfd2af6ad2588 for a while to give script authors some time to update. Let's remove it for good now.
* lua: remove a ton of unneeded parenthesesDudemanguy2023-11-021-4/+4
| | | | | | | | | | | For whatever reason, some of the lua code (particularly the osc and ytdl_hook) is full of a bunch of stuff like if (foo), if not (foo == nil), etc. The parenthesis aren't needed in lua and actually just look weird since nobody actually writes lua like this. You can see most of the other conditionals are written normally. So cleanup the style to match when the parenthesis clearly aren't doing anything. Not directly related, but also add some spaces on a few math operations while we're at it.
* defaults.lua: add a disabled parameter to timer constructorsMike Will2023-10-111-4/+6
| | | | | | | | Added to the functions `mp.add_timeout` and `mp.add_periodic_timer`. If the `disabled` argument is set to `true` or a truthy value, the timer will wait to be manually started with a call to its `resume()` method.
* lua/js: remove user-data helpersAvi Halachmi (:avih)2023-01-291-19/+0
| | | | | | | | | | | | | | | This reverts: 3fb4140c lua/defaults: add user_data helpers 68a20e7a javascript/defaults: add user_data helpers 00510379 lua/js: fix user_data_del util function As well as the lua/js parts of: 3ec2a098 docs: document new user-data property user-data and its sub-properties can be set/get/observed/deleted via the standard properties interface, so there's no need for additional helpers specific to user-data, which only added maintenance burden.
* lua/js: fix user_data_del util functionrcombs2023-01-281-1/+1
|
* lua/defaults: add user_data helpersrcombs2023-01-281-0/+19
|
* lua: command_native_async: make the callback optionalCogentRedTester2022-06-221-0/+1
| | | | | | | The documentation states that the callback is optional, but it actually was not. Now it's optional, as docuented.
* lua: command_native_async: always callback a-syncCogentRedTester2022-06-221-1/+1
| | | | | | | | | | | | | | | | | Previously if the raw command_native_async returned an error then the callback function was run directly. This meant that script writers potentially had to account for both synchronous and asynchronous logic in the callback, which can happen even with seemingly 'safe' commands if the mpv event queue is full. This was at odds with the Javascript implementation of the function, which always runs the callback asynchronously. Now the mp.add_timeout function is used to run the callback asynchronously on error, replicating the Javascript implementation. This provides consistency for developers in how the callback is handled in Lua, and increases consistency between the Lua and Javascript APIs.
* lua: remove mp.suspend, resume and resume_allsfan52021-12-151-3/+0
| | | | | | These functions were deprecated in v0.21.0 and no-ops since v0.23.0. The matching client API functions were removed in the previous commit.
* lua: fix timers comment (no-op)Avi Halachmi (:avih)2021-07-131-2/+3
| | | | | process_timers() doesn't return an absolute time. It returned delta>0 or nil before f73814b1 , and since f73814b1 it can also return 0.
* lua: idle observers: ensure timers are up-to-dateAvi Halachmi (:avih)2021-06-231-0/+9
| | | | | | | | | | | | | | | This fixes two issues, both of which resulted from the timers-wait period not being re-calculated after idle-observers were executed: - If timers were added from an idle observer then they could fire long after they were due (only when/if the next mpv event arrives). - Idle observers don't execute in zero time, and the wait period for the next timer was implicitly extended by the idle observers execution time (because it was calculated before the idle observers). This commit ensures that if idle-observers were executed, then the timers wait period is re-calculated, which solves both issues.
* lua: timers: don't block forever with slow callbacksAvi Halachmi (:avih)2021-06-231-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, process_timers() kept going as long as there were due timers, which could be for extended periods of time or even forever if there were slow timer callbacks with either periodic timers or if timers were added repeatedly. This prevented dequeuing mpv events, and subsequently, among others, prevented mpv from quitting until process_timers() completed. For instance, this caused process_timers() to never return: function render() <longer than 1/60 s on a slow system> end mp.add_periodic_timer(1/60, render) Similarly, it never returned if a timer callback always added a new one-shot which was already due by the time the callback completed. This commit ensures that process_timers() only executes callbacks which were due when it started, so that timers which are added (or repeated) during process_timers() will wait for the next iteration - after mpv events are dequeued. This has no performance impact under normal conditions (when callbacks complete before the next timer is due). Additionally, previously idle-observers were executed unconditionally after the timers because indeed there was nothing due when (if...) process_timers() completed. However, now process_timers() can return even if there are due timers, so skip idle-observers on such case.
* scripting (lua/js): utils.getpid: make wrapper of pid propertyAvi Halachmi (:avih)2021-05-011-0/+4
| | | | | | | | | We now have at least 3 scripting APIs which are trivial wrappers around properties: mp.get_mouse_pos, utils.getcwd, utils.getpid. After some discussion on IRC it was decided that it's easier for us to maintain them as trivial wrappers than to deprecate them and inflict pain on users and script authors, so currently no plan to deprecate.
* lua/js: mp.get_mouse_pos: use the mouse-pos propertyAvi Halachmi (:avih)2020-11-161-0/+5
| | | | | | | mp.get_mouse_pos() is undocumented and is no longer required - the property can be used officially by any client now, however, osc.lua uses it, and also some user scripts learnt to rely on it, so we keep it - as a trivial wrapper around the new mouse-pos property.
* lua: make hook processing more flexiblewm42020-08-051-2/+25
| | | | | | | This can now opt to not continue a hook after the hook callback returns. This makes it easier for scripts, and may make it unnecessary to run reentrant event loops etc. for scripts that want to wait before continuing while still running the event loop.
* lua: restore change detection with legacy OSD functionwm42020-05-011-4/+9
| | | | | | | | | | mp.set_osd_ass() (which was undocumented, or in other words, was not supposed to be used by external scripts) used to do change detection in the mpv C code. If the resolution or payload did not change, it was not re-rendered on the lower levels. Apparently this made some people sad, so fix it. (But only after I told them to fuck off.) (Well I didn't put it this way, but still.)
* lua: restore recent end-file event, and deprecate itwm42020-03-221-0/+9
| | | | | | | | | | | | Lua changed behavior for this specific event. I considered the change minor enough that it would not need to go through deprecation, but someone hit it immediately and ask on the -dev channel. It's probably better to restore the behavior. But mark it as deprecated, since it's problematic (mismatch with the C API). Unfortunately, no automatic warning is possible. (Or maybe it is, by playing sophisticated Lua tricks such as setting a metatable and overriding indexing, but let's not.)
* command: extend osd-overlay command with bounds reportingwm42020-03-061-1/+1
| | | | | | | | | | | | | | | | | | | | This is more or less a minimal hack to make _some_ text measurement functionality available to scripts. Since libass does not support such a thing, this simply uses the bounding box of the rendered text. This is far from ideal. Problems include: - using a bitmap bounding box - additional memory waste and/or flushing caches - dependency on window size - odd small deviations with different window sizes (run osd-test.lua and resize the window after each timer update; the bounding boxes aren't adjusted in an overly useful way) - inability to query the size _after_ actual rendering But I guess it's a start. Since I'm aware that it's crap, add a threat to the manpage that this may be changed/removed again. For now, I'm interested whether anyone will have use for it in its current form, as it's an often requested feature.
* lua: use new OSD propertywm42020-01-081-9/+6
| | | | | | | | See previous commit. A nice side-effect is that mp.get_osd_margins() is not a special Lua-only thing anymore. I didn't test whether this function still works as expected, though.
* lua: fix guard against division by 0wm42019-12-231-1/+1
| | | | | This was incorrectly converted from the original C code. Change it to what the original code used.
* lua: fix passing non-integers to mp.set_osd_ass()wm42019-12-231-0/+2
| | | | | | | | | | | | | | libass uses integers for PlayResX/Y, so the osd-overlay command also does. Lua (pre-5.3) does not have an integer type, but the command interface makes a difference anyway. If you pass a Lua number with a fractional part to an integer parameter (using mp.command_native()), it will result in an error and complain about incompatible types. I think that's fine, but since this behavior extends to mp.set_osd_ass(), this is a compatibility problem. Fix this by explicitly coercing the resolution parameters to integer numbers.
* client API, lua: add new API for setting OSD overlayswm42019-12-231-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | Lua scripting has an undocumented mp.set_osd_ass() function, which is used by osc.lua and console.lua. Apparently, 3rd party scripts also use this. It's probably time to make this a public API. The Lua implementation just bypassed the libmpv API. To make it usable by any type of client, turn it into a command, "osd-overlay". There's already a "overlay-add". Ignore it (although the manpage admits guiltiness). I don't really want to deal with that old command. Its main problem is that it uses global IDs, while I'd like to avoid that scripts mess with each others overlays (whether that is accidentally or intentionally). Maybe "overlay-add" can eventually be merged into "osd-overlay", but I'm too lazy to do that now. Scripting now uses the commands. There is a helper to manage OSD overlays. The helper is very "thin"; I only want to force script authors to use the ID allocation, which may help with putting multiple scripts into a single .lua file without causing conflicts (basically, avoiding singletons within a script's environment). The old set_osd_ass() is emulated with the new API. The JS scripting wrapper also provides a set_osd_ass() function, which calls internal mpv API. Comment that part (to keep it compiling), but I'm leaving it to @avih to finish the change.
* lua: batch-update key bindingswm42019-12-231-3/+11
| | | | | | | | | | | | | | Lua scripting implements key bindings by defining an input section with all the bindings in it. Every add_key_binding() call ran a mpv command to update this section. This caused a lot of spam at debug log levels. Reduce the spam and more it efficient by batching updates into a single mpv command when the script becomes inactive. This is pretty simple, because there's already the concept of idle handlers. This requires that the script actually goes to sleep, which might not happen in various extremely bogus corner cases, such as polling the mpv message queue with active waiting. Just don't do that.
* command, lua: add a way to share data between scriptswm42019-12-181-0/+24
| | | | | | | | | Very primitive and dumb, but fulfils its purpose for the next commits. I chose this specific implementation because it has the lowest footprint in command.c, without resorting to crazy hacks such as sending messages between scripts (which would be hard to coordinate especially on startup).
* lua: make later key bindings always have higher prioritywm42019-12-071-2/+13
| | | | | | | | | | | | | | | | | | | Later calls to mp.add_key_binding() should take priority over previous calls with the same key. Until now, the order was random (due to using table pairs() iteration order). Do this by simply sorting by a counter that is never reset. Since input.c also gives later bindings priority, this works out. Calling mp.remove_key_binding() on a newer binding makes an older still existing binding with the same key active again. New bindings override older ones, but do not overwrite them. I think these are good semantics for most use cases. (Note that the Lua code cannot determine whether two bindings use the same key. Keys are strings, and two different strings could refer to the same key. The code does not have access to input.c's key name normalization, so it cannot compare them.)
* lua: unbreak mp.add_key_binding(key, fn)Avi Halachmi (:avih)2019-11-301-1/+1
| | | | | | | Commit 311cc5b6 added the ability use flags while omitting name, but broke the case where both name and flags are omitted. Now omitting either name or flags or both works as documented.
* lua: make add_key_binding() rotate optional arguments correctlywm42019-11-231-1/+5
| | | | | | | | add_key_binding() makes the name argument optional (in weird Lua fashion), which did not work if there were additional arguments. So there is no way to avoid specifying a name while passing a rp argument. Fix this, declare this way of skipping the argument as deprecated, and allow passing name=nil as the preferred way to skip the name argument.
* input: add text produced by key to script key eventswm42019-11-221-3/+7
| | | | | | | Particularly for "any_unicode" mappings, so they don't have to special-case keys like '#' and ' ', which are normally mapped to symbolic names for input.conf reasons. (Though admittedly, this is a pretty minor thing, since API users could map these manually.)
* lua: complex key binding: use key_name like the docs sayAvi Halachmi (:avih)2019-11-201-1/+1
|
* lua: report key name for "complex" key bindingswm42019-11-191-4/+5
| | | | This might make certain use cases less of a mess.
* lua: actually unobserve properties in mp.unobserve_property()wm42019-10-241-0/+1
| | | | | | | | | Not doing this looked like a memory leak. This looks like an oversight in the commit that added it: a94020e25bc5f, possible brain damage? Fixes: #6823
* Merge branch 'master' into pr6360Jan Ekström2019-03-111-6/+3
|\ | | | | | | | | | | Manual changes done: * Merged the interface-changes under the already master'd changes. * Moved the hwdec-related option changes to video/decode/vd_lavc.c.
| * lua: execute idle handlers after timers have been processedOlivier Perret2019-01-161-6/+3
| | | | | | | | | | | | | | Idle handlers used to not be executed when timers were active Now they are executed: * After all expired timers have been executed * After all events have been processed (same as when there are no timers)
* | lua: expose mpv_abort_async_command()wm42018-05-241-3/+17
| | | | | | | | Also somewhat cleans up mp.command_native_async() error handling.
* | lua: reimplement mp.subprocess_detached() by invoking the "run" commandwm42018-05-241-0/+4
| | | | | | | | | | | | | | | | The "run" command is old. I'm not sure why the separate Lua implementation was added. But maybe it as because the "run" command used to be limited to a small number of arguments. This limit has been removed a while ago. In any case, the old implementation is not needed anymore.
* | lua: reimplement mp.subprocess() by invoking the new subprocess commandwm42018-05-241-0/+23
| | | | | | | | | | | | | | We keep mp.subprocess() with roughly the same semantics for compatibility with scripts (including the internal ytdl script). Seems to work with rhe ytdl wrapper. Not tested further.
* | lua: expose async commandswm42018-05-241-0/+21
|/ | | | Might be useful for some.
* client API: add a first class hook API, and deprecate old APIwm42018-03-261-10/+7
| | | | | | | | | | | | | | | As it turns out, there are multiple libmpv users who saw a need to use the hook API. The API is kind of shitty and was never meant to be actually public (it was mostly a hack for the ytdl script). Introduce a proper API and deprecate the old one. The old one will probably continue to work for a few releases, but will be removed eventually. There are some slight changes to the old API, but if a user followed the manual properly, it won't break. Mostly untested. Appears to work with ytdl_hook.
* lua: implement mp_utils.format_bytes_humanizedJulian2017-12-261-0/+10
|
* lua: implement mp.msg.traceNiklas Haas2017-12-151-0/+1
|
* lua: allow unregistration of idle handlersOlivier Perret2017-01-151-0/+10
|
* client API: turn mpv_suspend() and mpv_resume() into stubswm42016-11-221-6/+6
| | | | | | | | | | | As threatened by the API changes document. This commit also removes or stubs equivalent calls in IPC and Lua scripting. The stubs are left to maintain ABI compatibility. The semantics of the API functions have been close enough to doing nothing that this probably won't even break existing API users. Probably.
* lua: add API for registering idle handlerswm42016-09-211-0/+10
| | | | | This is only a functionality the Lua event dispatcher provides, rather than the libmpv client API.
* lua: run timers only after draining the event queuewm42016-09-211-12/+11
| | | | | | Instead of rechecking the timers every time after an event is read, do it only once the event queue is empty. This is probably slightly more efficient, and facilitates the next commit.
* Use - as command-name separator everywhereTimotej Lazar2016-07-141-3/+3
| | | | | | | Old-style commands using _ as separator (e.g. show_progress) were still used in some places, including documentation and configuration files. This commit updates all such instances to the new style (show-progress) so that commands are easier to find in the manual.
* lua: add timer:is_enabled() functionJulian2016-05-141-0/+4
| | | | | Allows to query if some timer is currently running or was stopped/killed.
* lua: don't require key for mp.add_key_binding()wm42016-03-261-3/+4
| | | | | Requested. The intention is that scripts can provide mappable actions for key bindings without setting a default key.
* lua: don't suspend core by default during script executionwm42016-03-181-1/+1
| | | | | | | | | This changes behavior somewhat. The old behavior can be restored by running "mp.use_suspend=true". It was originally introduced for the OSC, but I can't reproduce whatever misbehavior I was seeing. (See mp.suspend()/resume() for explanations what the suspend mechanism does.)
* lua: implement input_enable_section/input_disable_section via commandswm42015-08-061-1/+12
| | | | | | | | | | | | | | | Removes some more internal API calls from the Lua scripting backend. Which is good, because ideally the scripting backend would use libmpv functions only. One awkwardness is that mouse sections are still not supported by the public commands (and probably will never), so flags like allow-hide- cursor make no sense to an outside user. Also, the way flags are passed to the Lua function changes. But that's ok, because they're only undocumented internal functions, and not supposed to be used by script users. osc.lua only does due to historical reasons.
* lua: make mp.input_define_section use the define-section commandwm42015-08-061-0/+7
|
* input: allow - as separator between commands, instead of _wm42015-05-251-5/+5
| | | | | | | | | | Wnile it seems quite logical to me that commands use _ as word separator, while properties use -, I can't really explain the difference, and it tends to confuse users as well. So always prefer - as separator for everything. Using _ still works, and will probably forever. Not doing so would probably create too much chaos and confusion.
* lua: replace getcwd() implementationwm42015-03-241-0/+4
|
* Lua: add unpack shim for Lua 5.2/5.3 compatibility.torque2015-03-061-0/+2
| | | | | | | | | The global unpack function got moved to table.unpack in Lua 5.2, and it's only available as the global if 5.2 is built with compatibility enabled (the default). Lua 5.3 does not build with 5.1 compatibility by default. Fixes #1648.
* options: deprecate 'lua' based options/dirs for 'script'Avi Halachmi (:avih)2014-12-151-1/+1
| | | | | | | | | | | | - --lua and --lua-opts change to --script and --script-opts - 'lua' default script dirs change to 'scripts' - DOCS updated - 'lua-settings' dir was _not_ modified The old lua-based names/dirs still work, but display a warning. Signed-off-by: wm4 <wm4@nowhere>
* lua: don't ignore key press events for script key bindingswm42014-12-101-2/+2
| | | | Meh.
* lua: fully cleanup removed key bindingswm42014-12-031-0/