How can I pass an argument from a button?

Discuss your Lua playlist, album art and interface scripts.
datafreak
New Cone
New Cone
Posts: 6
Joined: 14 Jun 2016 02:56

How can I pass an argument from a button?

Postby datafreak » 14 Jun 2016 04:39

Hi

I want to dynamically add buttons to my extensions dialogue, which when clicked call a function with an argument, so the function can determine which button (or a value/ID) was clicked.

Like this ideally:

at runtime an arbitrary amount of these will be added, the button text and position can be generated at runtime that works..

Code: Select all

d:add_button("Button 1",my_function(1),1,1,1,1) d:add_button("Button 2",my_function(2),1,2,1,1) d:add_button("Button 3",my_function(3),1,3,1,1)
.. and so on

BUT it seems the add_button method? it does not support arguments in the parenthesis after the function name, it gives me error:

Code: Select all

my-extension.lua:60: dialog:add_button usage: (text, func)
The function my_function does exist and the add_button works when you remove the argument, or when you just have the function name with nothing else, but I want to pass the argument!

I just need some way of ID'ing which dynamically created button has been clicked, whether it's with tables, objects, dynamically created functions or anything, there must be a way.

I've been reading for too long and it's gone above my head so I'm hoping someone could help.

If not I guess i'll have to use a list, it's just a shame as dynamically added buttons in a grid otherwise work perfectly for what I'm trying to do (a custom bookmarking system).

Thanks!

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: How can I pass an argument from a button?

Postby mederi » 14 Jun 2016 12:44


datafreak
New Cone
New Cone
Posts: 6
Joined: 14 Jun 2016 02:56

Re: How can I pass an argument from a button?

Postby datafreak » 14 Jun 2016 17:11

Wow you are my hero, seriously, thanks so much mederi!

That lead me to the problem that the argument in the add_button function definition will be evaluated at click time, not at button creation time.
So I worked out one way to get my actual variable's value to stay on the button for click time:

Code: Select all

loadstring("button_grid[x] = d:add_button("Button " .. x,function() my_func(" .. x .. ") end,1,1,1,1)") ()
That works, as in, the buttons created do have the creation time value in their function call arguments.

Thanks so much, this has basically just made my whole extension feasible, I had lost hope thinking I had to spend a long time learning C++ to program what I want to do.

Next battle is probably global hotkeys for the extension *gulp*.

qazwiz
New Cone
New Cone
Posts: 4
Joined: 16 Jun 2017 04:37

Re: How can I pass an argument from a button?

Postby qazwiz » 16 Jun 2017 05:30

so? how's your extension?


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 4 guests