lua-users home
lua-l archive

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


Matthew Percival wrote:
G'Day,

	I have been searching around on this topic, and have not come up with
anything substantial, so I suspect there is currently no option for
this, but I thought it best to ask, in case a skilled Lua programmer
knows a way.  Quite simply, I want to check stdin to see if there is
anything currently buffered, and only perform stdin:read() if there is.
As a simple example:

i = 1
while (i != 0) do
	if (stdin:read("*ready")) then -- somehow test if it's ready
		i = stdin:read("*all")
	else
		print "Looping again...\n"
end

	So, if the user ever types a 0, the loop will exit; if the user types
nothing, it will continually print on the screen.  Perhaps a bad
example, but a nice, simple one.  Can this be done, or would something
like this have to be written in first?

I believe that this applies:

http://www.c-faq.com/osdep/readavail.html

In other words, there is no way to do this in standard C, as C does not provide non-blocking I/O.

That being said, it is possible to write a C module for "console" I/O which would provide this behavior on <insert-your-platform-of-choice>.

I don't know of any projects which do this.

					-Mark