I am currently creating a serial data logger program. I am wondering whether I am correctly using the event loop. I have found various approaches in the documentation and am not sure which one is best.
ui.run(win):wait()
or
win:show()
repeat
ui.update()
until not win.visible
or
win:show()
while win.visible do
ui.update()
To clarify my thoughts: I have a main window with various controls, including a Combobox to select the serial port. As long as no port has been selected, the other controls should be disabled.
Until now, I have displayed the window with “ui.rin(win):wait()” and then deactivated all other controls in the script. Once a port has been selected, I enabled the other controls via the event "Combobox.onSelect()". That means I have to disable or enable controls in different events.
Then I found somethin with async:
ui.run(win)
async(function()
while win.visible do
if not isnil(win.PortCombobox.selected) then
win.WM_DISABLE:enable()
else
win.WM_DISABLE:disable()
end
if not isnil(win.COM) then
if win.COM.isopen then
win.WM_START:disable()
else
win.WM_START:enable()
end
end
sleep()
ui.update()
end
end)
waitall()
I define the conditions for disabling or enabling various controls in the async function. Now I just have to define it in one place.
Is this a good way to program an app?