|
Can anyone explain why this code produces a line on the console that ticks up every second: function testw() while true do t = os.time() io.write(t, '\r') end end As does this (with less cursor movement) function testw() while true do t = os.time() io.write(t, '\r') while os.time() == t do io.write('\r') end end end But this code produces nothing: function testw() while true do t = os.time() io.write(t, '\r') while os.time() == t do io.write('') end end end As does this: function testw() while true do t = os.time() io.write(t, '\r') while os.time() == t do end end end It almost seems like an os call creates a need to flush the stdout buffer. BTW replacing \r with \n in the lines that writes the time creates a scrolling display as expected in all cases, it seems to be some interaction with \r in particular. On the other hand this: function testw() while true do t = os.time() io.write(t, '\r') os.execute('sleep 1') io.write('\r') end end does not work either so an extra write to flush the buffer is not enough. |