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.)
This commit is contained in:
Roberto Ierusalimschy
2019-07-31 10:43:51 -03:00
parent 35b4efc270
commit f645d31573
6 changed files with 70 additions and 41 deletions

View File

@@ -1572,6 +1572,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
else if EQ("error") {
lua_error(L1);
}
else if EQ("abort") {
abort();
}
else if EQ("throw") {
#if defined(__cplusplus)
static struct X { int x; } x;