Adds support for the __close value in the lfs.dir() iterator when using Lua 5.4. This requires no changes from the user, and ensures that the directory will be closed correctly even if you break from the loop.
For example, with uname -n set below 10000, this script crashes on Lua < 5.4, and works in Lua 5.4:
local lfs = require("lfs")
for t = 1, 10000 do
local i = 0
for e in lfs.dir("/usr/lib") do
i = i + 1
if i == 100 then
break
end
end
end
(This is not a forced example: I have hit this problem before when recursing over large directory trees and collecting files.)
Coverage decreased (-0.3%) to 81.922% when pulling 88044c606f12c47891c5cb63c2a350b470e88c08 on 5.4-iterator into 4f7e1b5a49575c77657b77bea383f79cddd768e3 on master.
Adds support for the
__close
value in thelfs.dir()
iterator when using Lua 5.4. This requires no changes from the user, and ensures that the directory will be closed correctly even if youbreak
from the loop.For example, with
uname -n
set below 10000, this script crashes on Lua < 5.4, and works in Lua 5.4:(This is not a forced example: I have hit this problem before when recursing over large directory trees and collecting files.)