Commit 8cb56e31 authored by Rémi Duraffort's avatar Rémi Duraffort

lua: fix hotkeys demo file.

parent 502a2fa8
...@@ -39,7 +39,7 @@ bindings = { ...@@ -39,7 +39,7 @@ bindings = {
function quit() function quit()
print("Bye-bye!") print("Bye-bye!")
vlc.quit() vlc.misc.quit()
end end
function demo() function demo()
...@@ -74,22 +74,16 @@ function action_trigger( action ) ...@@ -74,22 +74,16 @@ function action_trigger( action )
print("action_trigger:",tostring(action)) print("action_trigger:",tostring(action))
local a = actions[action] local a = actions[action]
if a then if a then
local date = vlc.misc.mdate() local ok, msg = pcall( a.func )
if a.delta and date > a.last + a.delta then if not ok then
a.times = 0 vlc.msg.err("Error while executing action `".. tostring(action) .."': "..msg)
else
a.times = a.times + 1
end end
a.last = date
table.insert(queue,action)
vlc.misc.signal()
else else
vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.") vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.")
end end
end end
function key_press( var, old, new, data ) function key_press( var, old, key, data )
local key = new
print("key_press:",tostring(key)) print("key_press:",tostring(key))
if bindings[key] then if bindings[key] then
action_trigger(bindings[key]) action_trigger(bindings[key])
...@@ -101,17 +95,7 @@ end ...@@ -101,17 +95,7 @@ end
vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press ) vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
--vlc.var.add_callback( vlc.object.libvlc(), "action-triggered", action_trigger ) --vlc.var.add_callback( vlc.object.libvlc(), "action-triggered", action_trigger )
while not die do while not vlc.misc.lock_and_wait() do
if #queue ~= 0 then
local action = actions[queue[1]]
local ok, msg = pcall( action.func )
if not ok then
vlc.msg.err("Error while executing action `"..queue[1].."': "..msg)
end
table.remove(queue,1)
else
die = vlc.misc.lock_and_wait()
end
end end
-- Clean up -- Clean up
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment