Prints not displaying just before a hang

Is there a way to force print statements to output like the fflush() function in C language?

It seems they don’t output immediately so when you have an infinite loop shortly after the print, you never see the output.

Hmmm, interesting. I am doing this:

function init(self)
	print("TEST")
	self.t = 0
	while true do
		self.t = self.t + 1
	end
end

and it prints fine before stalling. How does your code look?

I am not sure how the innards of print() work but you can try io.flush().

On which OS are you testing this? It could be that the buffer isn’t flushed and io.flush() would help like @sicher explained. You could also try:

 io.stderr:write("foobar")
 io.stdout:write("foobar")

But I’m not sure if it’s any different from a print()

Thanks for the replies - I’m on Windows 10.

Tried your various suggestions - nothing appears in the console window.