-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Lua5.1, Lua5.2, and Lua5.3 currently has no way of getting stdin input outside of manual in-console input. No matter what you pipe to luaw or lua, nothing actually gets sent to io.stdin for in-script use. In a recent update, I made it enabled to where you can use | and < to send files and strings to the program via stdin. I don't think I really set it up too good, but it works and I have a patch that I am working out at the time of writing.
The patch comes down to when what runs. ARGS.restore_console exists because I need to flag to re-enable tty for the post-exist flag -p. I will not be able to get stdin into my program and use -p without the hack, as this is due to Windows and Linux. It was a nasty hack that goes against the prettiness of the code I have, but hey. The hack has to do with organizing this process to allow tty to be reenabled and also be able to give scripts their data they want. Without the organization patch, piping and trying to -e a string will not work per trying to io.stdin:read() due to when the hack comes into effect.
More importantly though, Lua's code in liolib.c, if I am not mistaken, opens up 2 new files and treats them as a high level stdin and stdout. Using getc will allow for this ofc... you don't have to use the stdin file handle, in fact echo print('hi') | lua -i breaks in puc-lua the same way it does LuaConsole.... thus the hack I just brought up. Although, the cutesy that the puc-lua console is, it actually just executes whatever you pipe through it aka autodetection. Limiting, I know.
Lua kindly puts the files in the registry. So sweet of them, I think I might as well take the files for myself and fix the pipeline on user switch request. Idk if it will break the io lib. If it does I can use other synthetic ways I am sure. Although, its good to keep in mind that people are definitely now allowed to pipe streams to the program - in that 'stdin' could not be used for processing socket streams of data at varying intervals. I don't want to create an io library lol.
C:\git\LuaConsole\lua-5.3.5\src>echo print('hi') | lua -i
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
> hi
>
C:\git\LuaConsole\lua-5.3.5\src>