diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 10:43:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 10:43:51 -0300 |
| commit | f645d3157372c73573dff221c5b26691cb0e7d56 (patch) | |
| tree | 61adb1f332bbd8c0c0365b81cef8de47fa2ea06a /testes/api.lua | |
| parent | 35b4efc270db2418bc2cac6671575a45028061c3 (diff) | |
| download | lua-github-f645d3157372c73573dff221c5b26691cb0e7d56.tar.gz | |
To-be-closed variables must be closed on initialization
When initializing a to-be-closed variable, check whether it has a
'__close' metamethod (or is a false value) and raise an error if
if it hasn't. This produces more accurate error messages. (The
check before closing still need to be done: in the C API, the value
is not constant; and the object may lose its '__close' metamethod
during the block.)
Diffstat (limited to 'testes/api.lua')
| -rw-r--r-- | testes/api.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/testes/api.lua b/testes/api.lua index 3f7f7596..f6915c3e 100644 --- a/testes/api.lua +++ b/testes/api.lua @@ -1096,7 +1096,7 @@ do assert(type(a[1]) == "string" and a[2][1] == 11) assert(#openresource == 0) -- was closed - -- error + -- closing by error local a, b = pcall(T.makeCfunc[[ call 0 1 # create resource toclose -1 # mark it to be closed @@ -1105,6 +1105,15 @@ do assert(a == false and b[1] == 11) assert(#openresource == 0) -- was closed + -- non-closable value + local a, b = pcall(T.makeCfunc[[ + newtable # create non-closable object + toclose -1 # mark it to be closed (shoud raise an error) + abort # will not be executed + ]]) + assert(a == false and + string.find(b, "non%-closable value")) + local function check (n) assert(#openresource == n) end |
