Keyboard input

Hi. I just read about ruby yesterday after obtaining a copy of April 2002 linux magazine, and I’m quite impressed at how much like c++ it is, but easier. However a project that I may do in ruby instead of c++ (a software 3d api) will be useless unless I can get keyboard input in a non-blocking way. One thing that I have been thinking was using multithreading (which looks amazingly easy in ruby) and use the .collect() function, but does this block? Also will it pick up keys like the up arrow?

----KallDrexx

···


Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

“Matthew Shapiro” kalldrexx@programmer.net writes:

keyboard input in a non-blocking way. One thing that I have been
thinking was using multithreading (which looks amazingly easy in
ruby) and use the .collect() function, but does this block?

As long as you use the IO functions from the IO class, ruby won’t
block.

Also will it pick up keys like the up arrow?

That depends on what the C library returns you. If your C library
allows you to pick up the up arrow key using getc, then ditto for
IO#getc.

Now, if my reading of eval.c and sig is correct, then the thread
granularity of ruby is per AST node, and if a node takes more than 500
ticks (of what?, of system’s timer interrupt?), then it is pre-empted
except if Thread#critical is set.

Am I correct?

YS.