Hello all,

When attatching a function to a button event, I can use
button1:action(). However, in certain circunstances, it's not  good to
do it. See the code bellow:

require('iuplua')

function main(title)
local button1, vbox

button1 = iup.button{title = 'Botão 1'}
vbox = iup.vbox{button1}
return iup.dialog{vbox; title = title}
end

function button1_action()
iup.Message('Aviso', 'O botão 1 foi pressionado')
end

dlg = main('Teste')
dlg:show()
iup.MainLoop()

If I use button1:action, it was necessary to place it inside main
whereas I want to place it outside.

How to link button1 to the button1_action(?

One hypothesis could be:

button1 = iup.button{title = 'Botão 1', action = function ()
return button1_action()
 end}

It works, but this choice is low readable. I tried:

function main(title)
local button1, vbox

button1 = iup.button{title = 'Botão 1'}
iup.SetAttribute(button1, 'ACTION', 'button1_action')
vbox = iup.vbox{button1}
return iup.dialog{vbox; title = title}
end
Actually, I want to use iup.SetAttribute to link events. I could place
my callback without closures and without action = function()..

Why didn't iup.SetAttribute work?

Regards,

Luciano

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to