From 511d53a826760dd11cd82947184583e2d094e2d2 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Mar 2021 11:42:45 -0300 Subject: lua_settop/lua_pop closes to-be-closed variables The existence of 'lua_closeslot' is no reason for lua_pop not to close to-be-closed variables too. It is too error-prone for lua_pop not to close tbc variables being popped from the stack. --- manual/manual.of | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'manual') diff --git a/manual/manual.of b/manual/manual.of index 2e15839a..c69970d2 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -4253,12 +4253,8 @@ If the new top is greater than the old one, then the new elements are filled with @nil. If @id{index} @N{is 0}, then all stack elements are removed. -For compatibility reasons, -this function may close slots marked as to-be-closed @see{lua_toclose}, -and therefore it can run arbitrary code. -You should not rely on this behavior: -Instead, always close to-be-closed slots explicitly, -with @Lid{lua_closeslot}, before removing them from the stack. +This function can run arbitrary code when removing an index +marked as to-be-closed from the stack. } @@ -4347,19 +4343,22 @@ otherwise, returns @id{NULL}. @apii{0,0,m} Marks the given index in the stack as a -to-be-closed @Q{variable} @see{to-be-closed}. +to-be-closed slot @see{to-be-closed}. Like a to-be-closed variable in Lua, -the value at that index in the stack will be closed +the value at that slot in the stack will be closed when it goes out of scope. Here, in the context of a C function, to go out of scope means that the running function returns to Lua, -there is an error, +or there is an error, +or the slot is removed from the stack through +@Lid{lua_settop} or @Lid{lua_pop}, or there is a call to @Lid{lua_closeslot}. -An index marked as to-be-closed should neither be removed from the stack -nor modified before a corresponding call to @Lid{lua_closeslot}. +A slot marked as to-be-closed should not be removed from the stack +by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}, +unless previously deactivated by @Lid{lua_closeslot}. This function should not be called for an index -that is equal to or below an active to-be-closed index. +that is equal to or below an active to-be-closed slot. Note that, both in case of errors and of a regular return, by the time the @idx{__close} metamethod runs, -- cgit v1.2.3-55-g6feb