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').
This commit is contained in:
Roberto Ierusalimschy
2018-11-07 10:03:05 -02:00
parent 5e76a4fd31
commit b8fed93215
8 changed files with 48 additions and 47 deletions

View File

@@ -125,7 +125,7 @@ do
-- closing file by scope
local F = nil
do
local scoped f = assert(io.open(file, "w"))
local *toclose f = assert(io.open(file, "w"))
F = f
end
assert(tostring(F) == "file (closed)")
@@ -135,7 +135,7 @@ assert(os.remove(file))
do
-- test writing/reading numbers
local scoped f = assert(io.open(file, "w"))
local *toclose f = assert(io.open(file, "w"))
f:write(maxint, '\n')
f:write(string.format("0X%x\n", maxint))
f:write("0xABCp-3", '\n')
@@ -158,7 +158,7 @@ assert(os.remove(file))
-- testing multiple arguments to io.read
do
local scoped f = assert(io.open(file, "w"))
local *toclose f = assert(io.open(file, "w"))
f:write[[
a line
another line