Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Lua 5.4 __close value for lfs.dir() iterator #137

Merged
merged 2 commits into from
Apr 22, 2020
Merged

Conversation

hishamhm
Copy link
Member

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.)

@coveralls
Copy link
Collaborator

coveralls commented Apr 21, 2020

Coverage Status

Coverage decreased (-0.3%) to 81.922% when pulling 88044c6 on 5.4-iterator into 4f7e1b5 on master.

@hishamhm hishamhm merged commit 842505b into master Apr 22, 2020
@hishamhm hishamhm deleted the 5.4-iterator branch April 22, 2020 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants