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

Implement the file __close metamethod #78

Merged
merged 3 commits into from
Jan 21, 2022
Merged

Conversation

arnodel
Copy link
Owner

@arnodel arnodel commented Jan 19, 2022

In Lua 5.4 files have a __close metamethod that closes a file when it goes out of scope e.g.:

do
    local f <close> = io.open("hello")
    -- do stuff
end
-- At this point the file is closed for sure, even if not garbage-collected

This PR implements this metamethod

@codecov
Copy link

codecov bot commented Jan 19, 2022

Codecov Report

Merging #78 (e0a8f04) into lua5.4 (ca49b8e) will increase coverage by 1.48%.
The diff coverage is 96.33%.

❗ Current head e0a8f04 differs from pull request most recent head 13a5502. Consider uploading reports for the commit 13a5502 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           lua5.4      #78      +/-   ##
==========================================
+ Coverage   86.35%   87.83%   +1.48%     
==========================================
  Files          90       93       +3     
  Lines        9920    10240     +320     
==========================================
+ Hits         8566     8994     +428     
+ Misses       1063      956     -107     
+ Partials      291      290       -1     
Impacted Files Coverage Δ
lib/stringlib/pattern/builder.go 90.79% <ø> (ø)
runtime/debughooks.go 74.28% <40.00%> (+40.95%) ⬆️
lib/iolib/iolib.go 90.97% <64.70%> (-1.22%) ⬇️
runtime/luacont.go 91.00% <93.33%> (+0.95%) ⬆️
runtime/comp.go 93.10% <93.61%> (+0.37%) ⬆️
lib/base/base.go 88.76% <100.00%> (+0.12%) ⬆️
lib/base/warn.go 100.00% <100.00%> (ø)
lib/mathlib/mathlib.go 88.37% <100.00%> (+4.04%) ⬆️
lib/stringlib/format.go 95.04% <100.00%> (+1.03%) ⬆️
lib/stringlib/matching.go 100.00% <100.00%> (ø)
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b584d99...13a5502. Read the comment docs.

@arnodel arnodel added this to the Lua 5.4 milestone Jan 19, 2022
@arnodel arnodel merged commit fd02ebf into lua5.4 Jan 21, 2022
@arnodel arnodel deleted the lua-5.4-file-close-metamethod branch January 21, 2022 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants