lua-users home
lua-l archive

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


Le 22 sept. 2010 à 20:41, Thomas Harning Jr. a écrit :
> On Wed, Sep 22, 2010 at 2:32 PM, Fabien <fleutot+lua@gmail.com> wrote:
>> luac.exe offers a "-o -" option to dump bytecode to stdout.
>> Unfortunately, Windows considers stdout as an ASCII output, and therefore
>> translates all occurrences of "0x0a" into "0x0d, 0x0a", thus corrupting the
>> produced bytecode.
>> This can be checked by performing a binary diff between 1.luac and 2.luac,
>> produced by "luac -o 1.luac whatever.lua"  and "luac -o - whatever.lua >
>> 2.luac".
> This isn't so much a bug in Lua as it is a problem in Windows.  You
> could work around this by forcing stdout to be binary _setmode... but
> that's pretty ugly and platform specific.

In fact, this seems to be a bug in Lua and not in Windows from a theoretical point of view.

I don't have a copy of the C/ANSI standard here but in C99 standard, on section 7.19.3 paragraph 7, std(in/out/err) are defined to be text streams, and in section 7.19.2 paragraph 2, it is specified that some transformations may be applied by the system on text stream especially regarding the end of line character.

So here, even if I think its stupid, what is done on Windows is perfectly correct according to C99 and I don't think this is different in previous version of the standard.
The problem is more that Lua try to write binary data on a text stream and fortunately for us, this perfectly works on all UNIX, and too bad for Windows users, this is not the case for them.

Perhaps, one of the first time we see that Lua doesn't fully respect C standards...

Tom

PS: I don't ask for a change in Lua, but it can be a good thing to document it in the manual.