async()
launch the Task immediately, that's why ui.run()
is executed.
ui.run()
is a blocking function that will wait for the Window provided in argument to be closed
So the win:status("TWO")
call will be effective only when the Window is closed, so, you will never see the change in the Status
One thing to remember too is that when the program execution flow reaches the end of the program, it will end and exits immediately.
You achieve what you want to do this way :
local ui = require("ui")
local win = ui.Window("Test","fixed",250,100); win:center()
win:status("ONE")
-- creates an asynchronous and non blocking ui loop
async(function()
win:show()
while win.visible do
ui.update()
sleep()
end
end)
win:status("TWO")
-- needed here to see the change
sleep(2000)
-- use waitall() instead to wait until the Window is closed
-- waitall()