lua-users home
lua-l archive

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


It was thus said that the Great Egor Skriptunoff once stated:
> On Thu, Feb 24, 2022 at 11:09 PM Roberto Ierusalimschy wrote:
> 
> > > [1/4] Add -u flag to interpreter. Forces unbuffered standard streams.
> >
> > You can define a file 'u.lua' in your path with this code:
> >  io.stdin:setvbuf("no")
> >  io.stdout:setvbuf("no")
> >  io.stderr:setvbuf("no")
> > Once you do that, you now have a two-letter flag "-lu".
> 
> I'd like to have an option to reopen stdin/stdout in binary mode.
> It is currently impossible from Lua code.
> So, Lua scripts are unable to process and generate binary input/output on
> Windows.
> Other programs (written on C) read/write binary data in stdout/stdin,
> but the "lua.exe myscript.lua" process can not be piped to them.
> 
> It would be useful for "lua.exe" to have an option to force unbuffered
> binary standard streams.
> It does not matter how many letters it would consist of.

  If Lua could wrap the C function freopen() that would work.  C standard
says of freopen():

	If filename is a null pointer, the freopen function attempts to
	change the mode of the stream to that specified by mode, as if the
	name of the file currently associated with the stream had been used.
	It is implementation-defined which changes of mode are permitted (if
	any), and under what circumstances.

  -spc