lua-users home
lua-l archive

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


Hi, all!

(WinXP SP2, Lua 5.1.1)

I'm writing small utility, that takes some number of lua files,
pregenerated by Excel script, and merges them into single file, doing
some postprocessing. This utility should delete input files before it
exits.

For example (untested illustrational code):

 -- Sample input file looks like:
 -- return { table_data };
 --

 local result = { };
 for i = 1,9 do
   merge_to_result(result, dofile("filename_" .. i .. ".lua")
 end

 -- ... (*)

 for i = 1,9 do
   assert(os.remove("filename_" .. i .. ".lua"))
 end

The call to os.remove() fails, reporting the file is locked by
someprocess. If I add call to collectgarbage("collect") on line (*),
os.remove() succeeds. Looks like dofile() keeps file open until GC.

It is somewhat inconvenient. Is it a bug or intentional feature?

Thanks in advance,
Alexander.