Add parameters to callback function

Discuss your Lua playlist, album art and interface scripts.
DasEarl
New Cone
New Cone
Posts: 2
Joined: 19 Aug 2015 13:52

Add parameters to callback function

Postby DasEarl » 19 Aug 2015 14:02

Hello,

I made a script to seek through my videos.
Since I don't know how to give a callback
function a parameter, my code looks like this:

Code: Select all

require 'common' function descriptor () return {title = "Seek"; version = "0.1"; author = "DasEarl"; capabilities = {}} end function activate() print("Seek started") dlg = vlc.dialog("Seeker") dlg:add_button("10%", seek_10, 1, 1, 1, 1) dlg:add_button("20%", seek_20, 1, 2, 1, 1) dlg:add_button("30%", seek_30, 1, 3, 1, 1) dlg:add_button("40%", seek_40, 1, 4, 1, 1) dlg:add_button("50%", seek_50, 1, 5, 1, 1) dlg:add_button("60%", seek_60, 1, 6, 1, 1) dlg:add_button("70%", seek_70, 1, 7, 1, 1) dlg:add_button("80%", seek_80, 1, 8, 1, 1) dlg:add_button("90%", seek_90, 1, 9, 1, 1) end function seek_90() common.seek("90%") end function seek_80() common.seek("80%") end function seek_70() common.seek("70%") end function seek_60() common.seek("60%") end function seek_50() common.seek("50%") end function seek_40() common.seek("40%") end function seek_30() common.seek("30%") end function seek_20() common.seek("20%") end function seek_10() common.seek("10%") end function deactivate() print("Seek stopped") end function close() print("Seek closed") vlc.deactivate() end
calling

Code: Select all

dlg:add_button("10%", seek(10), 1, 9, 1, 1)
does not work

Thanks for you help

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Add parameters to callback function

Postby mederi » 19 Aug 2015 14:32

Try this:

Code: Select all

dlg:add_button("10%", function() seek(10) end, 1, 1, 1, 1) function seek(position) common.seek(position.."%") end

DasEarl
New Cone
New Cone
Posts: 2
Joined: 19 Aug 2015 13:52

Re: Add parameters to callback function

Postby DasEarl » 19 Aug 2015 17:14

Perfect. Many thanks

Code: Select all

require 'common' function descriptor() return {title = "Seek"; version = "0.1"; author = "DasEarl"; capabilities = {}} end function activate() print("Seek started") dlg = vlc.dialog("Seeker") dlg:add_button("10%", function() seek(10) end, 1, 1, 1, 1) dlg:add_button("20%", function() seek(20) end, 1, 2, 1, 1) dlg:add_button("30%", function() seek(30) end, 1, 3, 1, 1) dlg:add_button("40%", function() seek(40) end, 1, 4, 1, 1) dlg:add_button("50%", function() seek(50) end, 1, 5, 1, 1) dlg:add_button("60%", function() seek(60) end, 1, 6, 1, 1) dlg:add_button("70%", function() seek(70) end, 1, 7, 1, 1) dlg:add_button("80%", function() seek(80) end, 1, 8, 1, 1) dlg:add_button("90%", function() seek(90) end, 1, 9, 1, 1) end function seek(n) common.seek(n.."%") end function deactivate() print("Seek stopped") end function close() print("Seek closed") vlc.deactivate() end


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 0 guests