diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-13 13:07:53 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-13 13:07:53 -0200 |
commit | fdc25a1ebfe9968dcec390dd556375105aa0be40 (patch) | |
tree | 43759131636a501ec92475d453fd1a1c73bc8090 /manual | |
parent | 3b06f983ae0e57b90cdeb500c84bb524e5c3635b (diff) | |
download | lua-fdc25a1ebfe9968dcec390dd556375105aa0be40.tar.gz lua-fdc25a1ebfe9968dcec390dd556375105aa0be40.tar.bz2 lua-fdc25a1ebfe9968dcec390dd556375105aa0be40.zip |
New functions 'lua_resetthread' and 'coroutine.kill'
New functions to reset/kill a thread/coroutine, mainly (only?) to
close any pending to-be-closed variable. ('lua_resetthread' also
allows a thread to be reused...)
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/manual/manual.of b/manual/manual.of index 0e8e3d72..862d032b 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -3927,6 +3927,19 @@ and then pops the top element. | |||
3927 | 3927 | ||
3928 | } | 3928 | } |
3929 | 3929 | ||
3930 | @APIEntry{int lua_resetthread (lua_State *L);| | ||
3931 | @apii{0,?,-} | ||
3932 | |||
3933 | Resets a thread, cleaning its call stack and closing all pending | ||
3934 | to-be-closed variables. | ||
3935 | Returns a status code: | ||
3936 | @Lid{LUA_OK} for no errors in closing methods, | ||
3937 | or an error status otherwise. | ||
3938 | In case of error, | ||
3939 | leave the error object on the stack, | ||
3940 | |||
3941 | } | ||
3942 | |||
3930 | @APIEntry{int lua_resume (lua_State *L, lua_State *from, int nargs, | 3943 | @APIEntry{int lua_resume (lua_State *L, lua_State *from, int nargs, |
3931 | int *nresults);| | 3944 | int *nresults);| |
3932 | @apii{?,?,-} | 3945 | @apii{?,?,-} |
@@ -3948,11 +3961,8 @@ or returned by the body function. | |||
3948 | @Lid{LUA_OK} if the coroutine finishes its execution | 3961 | @Lid{LUA_OK} if the coroutine finishes its execution |
3949 | without errors, | 3962 | without errors, |
3950 | or an error code in case of errors @seeC{lua_pcall}. | 3963 | or an error code in case of errors @seeC{lua_pcall}. |
3951 | |||
3952 | In case of errors, | 3964 | In case of errors, |
3953 | the stack is not unwound, | 3965 | the error object is on the top of the stack. |
3954 | so you can use the debug API over it. | ||
3955 | The error object is on the top of the stack. | ||
3956 | 3966 | ||
3957 | To resume a coroutine, | 3967 | To resume a coroutine, |
3958 | you remove all results from the last @Lid{lua_yield}, | 3968 | you remove all results from the last @Lid{lua_yield}, |
@@ -6285,6 +6295,17 @@ it is not inside a non-yieldable @N{C function}. | |||
6285 | 6295 | ||
6286 | } | 6296 | } |
6287 | 6297 | ||
6298 | @LibEntry{coroutine.kill(co)| | ||
6299 | |||
6300 | Kills coroutine @id{co}, | ||
6301 | closing all its pending to-be-closed variables | ||
6302 | and putting the coroutine in a dead state. | ||
6303 | In case of error closing some variable, | ||
6304 | returns @false plus the error object; | ||
6305 | otherwise returns @true. | ||
6306 | |||
6307 | } | ||
6308 | |||
6288 | @LibEntry{coroutine.resume (co [, val1, @Cdots])| | 6309 | @LibEntry{coroutine.resume (co [, val1, @Cdots])| |
6289 | 6310 | ||
6290 | Starts or continues the execution of coroutine @id{co}. | 6311 | Starts or continues the execution of coroutine @id{co}. |
@@ -8648,6 +8669,11 @@ has been removed. | |||
8648 | When needed, this metamethod must be explicitly defined. | 8669 | When needed, this metamethod must be explicitly defined. |
8649 | } | 8670 | } |
8650 | 8671 | ||
8672 | @item{ | ||
8673 | When a coroutine finishes with an error, | ||
8674 | its stack is unwound (to run any pending closing methods). | ||
8675 | } | ||
8676 | |||
8651 | } | 8677 | } |
8652 | 8678 | ||
8653 | } | 8679 | } |