diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-07 10:03:05 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-07 10:03:05 -0200 |
| commit | b8fed93215a23a3f443c5b0126f0de1725771b44 (patch) | |
| tree | 1d7d29388b8a20fb7d0920d94b02a8040612314d /testes/files.lua | |
| parent | 5e76a4fd313a8690d300085c4e8fcb9dca50c01a (diff) | |
| download | lua-b8fed93215a23a3f443c5b0126f0de1725771b44.tar.gz lua-b8fed93215a23a3f443c5b0126f0de1725771b44.tar.bz2 lua-b8fed93215a23a3f443c5b0126f0de1725771b44.zip | |
New syntax for to-be-closed variables
The new syntax is <local *toclose x = f()>. The mark '*' allows other
attributes to be added later without the need of new keywords; it
also allows better error messages. The API function was also renamed
('lua_tobeclosed' -> 'lua_toclose').
Diffstat (limited to 'testes/files.lua')
| -rw-r--r-- | testes/files.lua | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/testes/files.lua b/testes/files.lua index a11c5e61..e68eb9b8 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -125,7 +125,7 @@ do | |||
| 125 | -- closing file by scope | 125 | -- closing file by scope |
| 126 | local F = nil | 126 | local F = nil |
| 127 | do | 127 | do |
| 128 | local scoped f = assert(io.open(file, "w")) | 128 | local *toclose f = assert(io.open(file, "w")) |
| 129 | F = f | 129 | F = f |
| 130 | end | 130 | end |
| 131 | assert(tostring(F) == "file (closed)") | 131 | assert(tostring(F) == "file (closed)") |
| @@ -135,7 +135,7 @@ assert(os.remove(file)) | |||
| 135 | 135 | ||
| 136 | do | 136 | do |
| 137 | -- test writing/reading numbers | 137 | -- test writing/reading numbers |
| 138 | local scoped f = assert(io.open(file, "w")) | 138 | local *toclose f = assert(io.open(file, "w")) |
| 139 | f:write(maxint, '\n') | 139 | f:write(maxint, '\n') |
| 140 | f:write(string.format("0X%x\n", maxint)) | 140 | f:write(string.format("0X%x\n", maxint)) |
| 141 | f:write("0xABCp-3", '\n') | 141 | f:write("0xABCp-3", '\n') |
| @@ -158,7 +158,7 @@ assert(os.remove(file)) | |||
| 158 | 158 | ||
| 159 | -- testing multiple arguments to io.read | 159 | -- testing multiple arguments to io.read |
| 160 | do | 160 | do |
| 161 | local scoped f = assert(io.open(file, "w")) | 161 | local *toclose f = assert(io.open(file, "w")) |
| 162 | f:write[[ | 162 | f:write[[ |
| 163 | a line | 163 | a line |
| 164 | another line | 164 | another line |
