[luatex] odd read('*a') behaviour

Stephan Hennig sh-list at posteo.net
Fri Jun 26 23:08:54 CEST 2015


Hi,

I'm observing strange behaviour when reading from files via read('*a').
 Attached is a Lua script read.lua, which reads a file given as argument
twice.

First, it reads the file into a string at once using read('*a') and
outputs it.  After that, the same file is re-opened.  The first line is
read using read('*l').  Then, the remainder is read using read('*a').
Both strings are output.

The Lua script read.lua has Unix line endings (which might be relevant,
but I don't know).

When calling this script on Windows as

  texlua read.lua read.lua

the output is

> $ texlua read.lua read.lua
> --- BEGIN ---
> -- Read file at once.
> local fin = assert(io.open(arg[1], 'r'))
> local full = fin:read('*a')
> print(full)
> fin:close()
> -- Read file in two steps.
> local fin = assert(io.open(arg[1], 'r'))
> local first = fin:read('*l')
> print(first)
> local tail = fin:read('*a')
> print(tail)
> fin:close()
> --- END ---
> 
> --- BEGIN ---
> -- BEGIN ---
> -- Read file at once.
> local fin = assert(io.open(arg[1], 'r'))
> local full = fin:read('*a')
> print(full)
> fin:close()
> -- Read file in two steps.
> local fin = assert(io.open(arg[1], 'r'))
> local first = fin:read('*l')
> print(first)
> local tail = fin:read('*a')
> print(tail)
> fin:close()
> --- END ---

In the second attempt, the first line is printed twice, though not
completely.  The first minus character is missing.  (When removing the
first comment line completely from the script, even more characters are
missing from the then first line.)

Attached is another file german.tr, which is a translate file for Patgen
(the file can also be downloaded at
<URL:http://repo.or.cz/w/wortliste.git/tree/HEAD:/daten>).  Calling the
script on this file shows even more bizarre behaviour.  File german.tr
is output only once.  In the second attempt, only the first line " 2 2"
is read and output.  The second call to read('*a') doesn't seem to read
anything.

Affected:

* Windows 7, TL 2015
> This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/W32TeX) (rev 5238)
* Windows 7, TL 2014
> This is LuaTeX, Version beta-0.79.1 (TeX Live 2014/W32TeX) (rev 4971)

Not affected:

* Ubuntu 14.04, TL 2013
> This is LuaTeX, Version beta-0.76.0-2013121407  (TeX Live 2013/dev/Debian) (rev 4627)
* Windows 7, PUC Lua 5.2.3
* Ubuntu 14.04, PUC Lua 5.2.3

So this is probably a Windows only issue with LuaTeX.  Can anybody
confirm the buggy behaviour on other platforms?

Best regards,
Stephan Hennig
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: german.tr
URL: <http://tug.org/pipermail/luatex/attachments/20150626/aa558743/attachment.ksh>
-------------- next part --------------
--- BEGIN ---
-- Read file at once.
local fin = assert(io.open(arg[1], 'r'))
local full = fin:read('*a')
print(full)
fin:close()
-- Read file in two steps.
local fin = assert(io.open(arg[1], 'r'))
local first = fin:read('*l')
print(first)
local tail = fin:read('*a')
print(tail)
fin:close()
--- END ---


More information about the luatex mailing list