lua-users home
lua-l archive

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



* On 2009-08-12 Michael Newberry <mnewberry@mirametrics.com> wrote  :

> I've been using lua for almost 15 years and I've never had to use the io package before now. I can't get it to work. The fragment below returns a nil string.
> 
> I know the file name (sName, which is a full path) is good and that the file has multiple lines of text inside it. I printed the handle (nFile) returned by io.open and it is non zero.
> 
> 
> nFile, sMsg = io.open( sName, "r" )
> if not nFile then Exit(sMsg) end
> 
> for i = 1, 10000000 do
>   local sLine = io.read("*line")

You're reading from stdin, instead of from your newly opened filehandle.
Try:

local sLine = nFile:read("*l")

-- 
:wq
^X^Cy^K^X^C^C^C^C