From 017b3fa9dbbed1bcd5711599e42513daf5009fd0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 6 Sep 2014 17:02:47 +0200 Subject: lua: synchronously wait until scripts are loaded This makes the player wait until each script is loaded. Do this to give the script a chance to setup all its event handlers. It might also be useful to allow a script to change options that matter for playback. While waiting for a script to be loaded, the player actually accepts input. This is needed because the scripts can execute player commands anyway while they are being "loaded". The player won't react to most commands though: it can't quit or navigate the playlist in this state. For deciding whether a script is finally loaded, we use a cheap hack: if mpv_wait_event() is called, it's considered loaded. Let's hope this is good enough. I think it's better than introducing explicit API for this. Although I'm sure this will turn out as too simplistic some time in the future, the same would probably happen with a more explicit API. --- DOCS/man/lua.rst | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'DOCS') diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index d8791e7381..147563a964 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -47,6 +47,15 @@ The event loop will wait for events and dispatch events registered with ``mp.register_event``. It will also handle timers added with ``mp.add_timeout`` and similar (by waiting with a timeout). +Since mpv 0.6.0, the player will wait until the script is fully loaded before +continuing normal operation. The player considers a script as fully loaded as +soon as it starts waiting for mpv events (or it exits). In practice this means +the player will more or less hang until the script returns from the main chunk +(and ``mp_event_loop`` is called), or the script calls ``mp_event_loop`` or +``mp.dispatch_events`` directly. This is done to make it possible for a script +to fully setup event handlers etc. before playback actually starts. In older +mpv versions, this happened asynchronously. + mp functions ------------ -- cgit v1.2.3