lua-users home
lua-l archive

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


There are two Lua programs involved.  The first reads the directory (this is
Win/XP) and via "dofile" invokes the second for each matching file name.
The invoked program receives two arguments which are file names.  The first
is a name from the directory that matches the relevant criteria, the second
is file name which is the same for all invocations.  The second program
extracts data from the input file, and writes this data to the output file.
This output file is opened with the "a" (append) attribute.

In the original attempt, I neglected to use "io.close()" for the two files.
Out of 34 invocations, three lines in this output file were overlaid.  I
traced this data, and copied two of the problem causing files to a directory
by themselves.  I reran the programs, and the botched data was still
present.  I then added the io.close() for the two files at the appropriate
place, and this problem went away.

My understanding was that Lua closed files at program end time.  Is this
correct?  I am puzzled because this worked for 31 of the 34 cases.  Here is
a little pseudocode:

  f =  assert(io.open(arg[1], "r"))
  g =  assert(io.open(arg[2], "a"))

--
-- process data
--

--
--  without the close, 31 0f 34 invocations work
--  all work with it 
--
--  f:close()
--  g:close()
--











CONFIDENTIALITY NOTICE:  This E-mail message and all attachments, which originated from Sealy Management Company Inc, are intended solely for the use of the intended recipient or entity and may contain legally privileged and confidential information.  If the reader of this message is not the intended recipient, you are hereby notified that any reading, disclosure, dissemination, distribution, copying or other use of this message is strictly prohibited.  If you have received this message in error, please notify the sender of the message immediately and delete this message and all attachments, including all copies or backups thereof, from your system.  You may also reach us by phone at 205-391-6000.  Thank you.