lua-users home
lua-l archive

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


On Oct 22, 2013, at 3:11 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:

>> fh:read("*l")  will apparently not return more than 1024 char.
> 
> If you're reading from the terminal, there will be a limit imposed by the OS.
> See http://stackoverflow.com/questions/19421858/lua-io-read-doesnt-work-on-long-strings
> 
>> If there are more it rolls over and returns a fragment from the end of the line.
> 
> I've never seen this.
> 
> Could you post a simple program and data that exhibits this problem?
> 
>> On a related question is there a limit to the number of statements or char that loadstring() can handle?
> 
> There is a limit on the number of VM instructions generated but you're
> unlikely to reach this.
> 
Here is a session with the interpreter that shows this:

Joses-MacBook-Pro:luawork jtorrebueno$ lua
Lua 5.2.0  Copyright (C) 1994-2011 Lua.org, PUC-Rio
> ifh = io.open('arenato')
> =ifh
file (0x7fff7c7a10a0)
> t = ifh:read()
> =t
ount =    2.0000, } return genotype
> ifh:seek('set')
> t = ifh:read('*a')
> =t
local genotype= {[1] =   1.0000, [2] =   1.0000, [3] =   1.0000, [4] =   1.0000, [5] =   1.0000, [6] =   1.0000, [7] =   1.0000, [8] =   1.0000, [9] =   1.0000, [10] =   1.0000, [11] =   1.0000, [12] =   1.0000, [13] =   1.0000, [14] =   1.0000, [15] =   1.0000, [16] =   1.0000, [17] =   1.0000, [18] =   1.0000, [19] =   1.0000, [20] =   1.0000, [21] =   1.0000, parent1 =  "B", pushed =  1382414143.0000, name =  "G__1_1_1_1_1__1_1_1_1_1__1_1_1_1_1__1_1_1_1_1__1__E", pushcount =    2.0000, } return genotype
> 

The second time t is read the value is wrapped to display but it is one line.

This is in OSX.  My intent is to create a file which serves as a combination of a log and a fifo so one program is adding lines that when put through loadstring yield a table and another program is reading the file and whenever a line is added it gets the most current version of the table.  When there is only one version of the table and it is exchanged between two programs by writing a file and reading it with loadfile this works, I had thought to write the code as a single line with line buffering and use the file pointer as the mechanism for the reader to know if there were a new version of the table.