4

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

DarkWiiPlayer
  • 6,871
  • 3
  • 23
  • 38

1 Answers1

1

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

Community
  • 1
  • 1
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • Thanks for the answer :) I don't need this right now, I was just wondering if it was possible to do it in lua (In case I ever need to do it). It's a shame lua doesn't support this by itself =/ – DarkWiiPlayer Oct 13 '16 at 10:50
  • @DarkWiiPlayer , lua is very simple language which has got very simple binding with any pure C code (library) – Vyacheslav Oct 13 '16 at 10:57
  • Yeah I know that, and I appreciate it a lot. But it seems this can be implemented in pure C in a few lines, so I think it could be worth having that in lua. Maybe there is a good reason why it's not though, and I'm just not seeing it. – DarkWiiPlayer Oct 13 '16 at 11:00
  • Because its not possible on `Pure` C. And there already exists many Lua libs which allows do this. – moteus Oct 13 '16 at 11:20