lua-users home
lua-l archive

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


On Mon, Feb 28, 2022 at 11:37 AM Gé Weijers <ge@weijers.org> wrote:
>
>
>
> On Fri, Feb 25, 2022 at 4:50 PM Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
>>
>>
>> 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.
>
>
> The problem is that there is no portable way of doing this. In Windows (according to MS documentation) you could do something like
>
> int result = _setmode(_fileno(stdin), _O_BINARY);
>
> to set stdin and/or stdout to binary mode.
>
>
> --
> Gé

Solving the binary/text and buffered/unbuffered mode portably in Lua
is somewhat annoying, whereas it could be done with new,
backwards-compatible -b and -u interpreter switches plus adequate use
of #ifdef LUA_USE_POSIX / LUA_USE_WINDOWS.

However, I am left with the impression that my patchset has hardly won
a consensus here, and especially not [1/4] to make streams unbuffered
using C89 functions only and in backwards-compatible fashion, so a
similar patch to add a -b flag for binary mode and using Windows API
calls seems even less likely to be accepted.


Olexa Bilaniuk