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 /lvm.c | |
parent | 35b4efc270db2418bc2cac6671575a45028061c3 (diff) | |
download | lua-f645d3157372c73573dff221c5b26691cb0e7d56.tar.gz lua-f645d3157372c73573dff221c5b26691cb0e7d56.tar.bz2 lua-f645d3157372c73573dff221c5b26691cb0e7d56.zip |
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 'lvm.c')
-rw-r--r-- | lvm.c | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -1739,10 +1739,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1739 | vmbreak; | 1739 | vmbreak; |
1740 | } | 1740 | } |
1741 | vmcase(OP_TFORPREP) { | 1741 | vmcase(OP_TFORPREP) { |
1742 | if (!ttisnil(s2v(ra + 3))) { /* is 'toclose' not nil? */ | 1742 | /* create to-be-closed upvalue (if needed) */ |
1743 | /* create to-be-closed upvalue for it */ | 1743 | halfProtect(luaF_newtbcupval(L, ra + 3)); |
1744 | halfProtect(luaF_newtbcupval(L, ra + 3)); | ||
1745 | } | ||
1746 | pc += GETARG_Bx(i); | 1744 | pc += GETARG_Bx(i); |
1747 | i = *(pc++); /* go to next instruction */ | 1745 | i = *(pc++); /* go to next instruction */ |
1748 | lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i)); | 1746 | lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i)); |