diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-09 11:42:45 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-09 11:42:45 -0300 |
| commit | 511d53a826760dd11cd82947184583e2d094e2d2 (patch) | |
| tree | 60dc1a2da1198fc7c9e058b794b03c757e0c48f7 /manual | |
| parent | f5df7f91f70234850484d26caf24e71e001e5304 (diff) | |
| download | lua-511d53a826760dd11cd82947184583e2d094e2d2.tar.gz lua-511d53a826760dd11cd82947184583e2d094e2d2.tar.bz2 lua-511d53a826760dd11cd82947184583e2d094e2d2.zip | |
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.
Diffstat (limited to 'manual')
| -rw-r--r-- | manual/manual.of | 23 |
1 files changed, 11 insertions, 12 deletions
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, | |||
| 4253 | then the new elements are filled with @nil. | 4253 | then the new elements are filled with @nil. |
| 4254 | If @id{index} @N{is 0}, then all stack elements are removed. | 4254 | If @id{index} @N{is 0}, then all stack elements are removed. |
| 4255 | 4255 | ||
| 4256 | For compatibility reasons, | 4256 | This function can run arbitrary code when removing an index |
| 4257 | this function may close slots marked as to-be-closed @see{lua_toclose}, | 4257 | marked as to-be-closed from the stack. |
| 4258 | and therefore it can run arbitrary code. | ||
| 4259 | You should not rely on this behavior: | ||
| 4260 | Instead, always close to-be-closed slots explicitly, | ||
| 4261 | with @Lid{lua_closeslot}, before removing them from the stack. | ||
| 4262 | 4258 | ||
| 4263 | } | 4259 | } |
| 4264 | 4260 | ||
| @@ -4347,19 +4343,22 @@ otherwise, returns @id{NULL}. | |||
| 4347 | @apii{0,0,m} | 4343 | @apii{0,0,m} |
| 4348 | 4344 | ||
| 4349 | Marks the given index in the stack as a | 4345 | Marks the given index in the stack as a |
| 4350 | to-be-closed @Q{variable} @see{to-be-closed}. | 4346 | to-be-closed slot @see{to-be-closed}. |
| 4351 | Like a to-be-closed variable in Lua, | 4347 | Like a to-be-closed variable in Lua, |
| 4352 | the value at that index in the stack will be closed | 4348 | the value at that slot in the stack will be closed |
| 4353 | when it goes out of scope. | 4349 | when it goes out of scope. |
| 4354 | Here, in the context of a C function, | 4350 | Here, in the context of a C function, |
| 4355 | to go out of scope means that the running function returns to Lua, | 4351 | to go out of scope means that the running function returns to Lua, |
| 4356 | there is an error, | 4352 | or there is an error, |
| 4353 | or the slot is removed from the stack through | ||
| 4354 | @Lid{lua_settop} or @Lid{lua_pop}, | ||
| 4357 | or there is a call to @Lid{lua_closeslot}. | 4355 | or there is a call to @Lid{lua_closeslot}. |
| 4358 | An index marked as to-be-closed should neither be removed from the stack | 4356 | A slot marked as to-be-closed should not be removed from the stack |
| 4359 | nor modified before a corresponding call to @Lid{lua_closeslot}. | 4357 | by any other function in the API except @Lid{lua_settop} or @Lid{lua_pop}, |
| 4358 | unless previously deactivated by @Lid{lua_closeslot}. | ||
| 4360 | 4359 | ||
| 4361 | This function should not be called for an index | 4360 | This function should not be called for an index |
| 4362 | that is equal to or below an active to-be-closed index. | 4361 | that is equal to or below an active to-be-closed slot. |
| 4363 | 4362 | ||
| 4364 | Note that, both in case of errors and of a regular return, | 4363 | Note that, both in case of errors and of a regular return, |
| 4365 | by the time the @idx{__close} metamethod runs, | 4364 | by the time the @idx{__close} metamethod runs, |
