lua-users home
lua-l archive

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


On Thu, Mar 20, 2014 at 4:08 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> function getch_unix()
>         os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
>         local key = io.read(1)
>         os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
>         return(key);
> end

That is indeed ingenious!  I was about to suggest using luaposix and use select.

The point is that there's no platform-independent way of doing this....

For Windows, you can get async i/o on the console using winapi:

http://stevedonovan.github.io/winapi/api.html#get_console

This returns a File object which has a read_async method, which you
pass a callback to receive anything read.