lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On May 14, 2013, at 2:20 PM, Jose Torre-Bueno <jtorrebueno@cox.net> wrote:

> 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
> 
> 
> 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
> 

I have a partial answer.  This code behaves as expected:

function testw()
	while true do
		t = os.time()
		io.write(t, '\r')
		io.stdout:flush()
		os.execute('sleep 1')
	end
end

The question remains why does an os call create a need to flush the stdout buffer?





Jose Torre-Bueno
jtorrebueno@cox.net