Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read data from stdio without blocking?

Tags:

input

stdio

lua

This question has been haunting me for a while now; is there a way in lua to check if there is any data available on stdio and only then read it?

For example; let's say I have some sort of server that is doing its important stuff that shouldn't be interrupted by a blocking io.read() function, but I still want to be able to input commands on the console.

I have tried io.read(0) but even that blocks until it gets an EOF

like image 489
DarkWiiPlayer Avatar asked Feb 04 '26 18:02

DarkWiiPlayer


1 Answers

I would suggest to write a custom pure C-library to check it.

https://stackoverflow.com/a/26949111/1979882

here an example to how create a C-library for Lua. http://cs.brynmawr.edu/Courses/cs380/fall2011/luar-topics2.pdf

like image 112
Vyacheslav Avatar answered Feb 06 '26 21:02

Vyacheslav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!