summaryrefslogtreecommitdiffstats
path: root/player/lua/defaults.lua
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-10 21:03:59 +0100
committerwm4 <wm4@nowhere>2014-02-10 21:03:59 +0100
commit206616b697672d973b24330af9b094ac851f7ca4 (patch)
tree5baea012aa584c11f573373c1c7cbeddced209f5 /player/lua/defaults.lua
parent88ae914b1ef2b76362c527985bd459b0d8226d45 (diff)
downloadmpv-206616b697672d973b24330af9b094ac851f7ca4.tar.bz2
mpv-206616b697672d973b24330af9b094ac851f7ca4.tar.xz
lua: port to client API
This is partial only, and it still accesses some MPContext internals. Specifically, chapter and track lists are still read directly, and OSD access is special-cased too. The OSC seems to work fine, except using the fast-forward/backward buttons. These buttons behave differently, because the OSC code had certain assumptions how often its update code is called. The Lua interface changes slightly. Note that this has the odd property that Lua script and video start at the same time, asynchronously. If this becomes an issue, explicit synchronization could be added.
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r--player/lua/defaults.lua47
1 files changed, 42 insertions, 5 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 4b5e5e6126..7dca478252 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -52,18 +52,31 @@ function mp.set_mouse_area(x0, y0, x1, y1, section)
mp.input_set_section_mouse_area(section or default_section, x0, y0, x1, y1)
end
--- called by C on script_dispatch input command
-function mp_script_dispatch(id, event)
- local cb = callbacks[id]
+local function script_dispatch(event)
+ local cb = callbacks[event.arg0]
if cb then
- if event == "press" and cb.press then
+ if event.type == "press" and cb.press then
cb.press()
- elseif event == "keyup_follows" and cb.before_press then
+ elseif event.type == "keyup_follows" and cb.before_press then
cb.before_press()
end
end
end
+-- used by default event loop (mp_event_loop()) to decide when to quit
+mp.keep_running = true
+
+local event_handlers = {}
+
+function mp.register_event(name, cb)
+ event_handlers[name] = cb
+ mp.request_event(name, true)
+end
+
+-- default handlers
+mp.register_event("shutdown", function() mp.keep_running = false end)
+mp.register_event("script-input-dispatch", script_dispatch)
+
mp.msg = {
log = mp.log,
fatal = function(...) return mp.log("fatal", ...) end,
@@ -79,4 +92,28 @@ _G.print = mp.msg.info
package.loaded["mp"] = mp
package.loaded["mp.msg"] = mp.msg
+_G.mp_event_loop = function()
+ wait = 0
+ while mp.keep_running do
+ -- Drop all locks - important especially if an error happened while
+ -- locked, and the error was handled, but the lock not dropped.
+ if wait > 0 then
+ mp.resume("all")
+ end
+ local e = mp.wait_event(wait)
+ if e.event == "none" then
+ wait = 1e20
+ else
+ -- Empty the event queue while suspended; otherwise, each
+ -- event will keep us waiting until the core suspends again.
+ mp.suspend()
+ wait = 0
+ local handler = event_handlers[e.event]
+ if handler then
+ handler(e)
+ end
+ end
+ end
+end
+
return {}