Typically the GUI and your application are separated because of the reactive nature of the GUI library. Most of your code for reacting to GUI events will go into a GUIObjects event handler.
-- # ...
myButton.eventHandler = function(app, instance, event)
if event == "touch" then
-- # react to touch event. Alter state, etc...
end
end
I don't have the time to test this my self but you could try using OpenOS threads to give control back to your main script.
-- # ... more stuff up here
local thread = require 'thread'
-- # Gui logic n stuff...
-- # This will now run whenever the