diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-03 13:11:20 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-03 13:11:20 -0300 |
commit | 514d94274853e6f0dfd6bb2ffa2e1fc64db926dd (patch) | |
tree | e024ebca966e8a84a7997c3908b74bb941dcbd50 | |
parent | 4a3fd8488d617aa633f6b8be85e662653b100a59 (diff) | |
download | lua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.tar.gz lua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.tar.bz2 lua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.zip |
'coroutine.kill' renamed 'coroutine.close'
-rw-r--r-- | lcorolib.c | 6 | ||||
-rw-r--r-- | manual/manual.of | 29 | ||||
-rw-r--r-- | testes/coroutine.lua | 22 |
3 files changed, 29 insertions, 28 deletions
@@ -165,7 +165,7 @@ static int luaB_corunning (lua_State *L) { | |||
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | static int luaB_kill (lua_State *L) { | 168 | static int luaB_close (lua_State *L) { |
169 | lua_State *co = getco(L); | 169 | lua_State *co = getco(L); |
170 | int status = auxstatus(L, co); | 170 | int status = auxstatus(L, co); |
171 | switch (status) { | 171 | switch (status) { |
@@ -182,7 +182,7 @@ static int luaB_kill (lua_State *L) { | |||
182 | } | 182 | } |
183 | } | 183 | } |
184 | default: /* normal or running coroutine */ | 184 | default: /* normal or running coroutine */ |
185 | return luaL_error(L, "cannot kill a %s coroutine", statname[status]); | 185 | return luaL_error(L, "cannot close a %s coroutine", statname[status]); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
@@ -195,7 +195,7 @@ static const luaL_Reg co_funcs[] = { | |||
195 | {"wrap", luaB_cowrap}, | 195 | {"wrap", luaB_cowrap}, |
196 | {"yield", luaB_yield}, | 196 | {"yield", luaB_yield}, |
197 | {"isyieldable", luaB_yieldable}, | 197 | {"isyieldable", luaB_yieldable}, |
198 | {"kill", luaB_kill}, | 198 | {"close", luaB_close}, |
199 | {NULL, NULL} | 199 | {NULL, NULL} |
200 | }; | 200 | }; |
201 | 201 | ||
diff --git a/manual/manual.of b/manual/manual.of index 687a5b89..eb4e671d 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -864,7 +864,7 @@ Unlike @Lid{coroutine.resume}, | |||
864 | the function created by @Lid{coroutine.wrap} | 864 | the function created by @Lid{coroutine.wrap} |
865 | propagates any error to the caller. | 865 | propagates any error to the caller. |
866 | In this case, | 866 | In this case, |
867 | the function also kills the coroutine @seeF{coroutine.kill}. | 867 | the function also closes the coroutine @seeF{coroutine.close}. |
868 | 868 | ||
869 | As an example of how coroutines work, | 869 | As an example of how coroutines work, |
870 | consider the following code: | 870 | consider the following code: |
@@ -1554,7 +1554,7 @@ Similarly, if a coroutine ends with an error, | |||
1554 | it does not unwind its stack, | 1554 | it does not unwind its stack, |
1555 | so it does not close any variable. | 1555 | so it does not close any variable. |
1556 | You should either use finalizers | 1556 | You should either use finalizers |
1557 | or call @Lid{coroutine.kill} to close the variables in these cases. | 1557 | or call @Lid{coroutine.close} to close the variables in these cases. |
1558 | However, note that if the coroutine was created | 1558 | However, note that if the coroutine was created |
1559 | through @Lid{coroutine.wrap}, | 1559 | through @Lid{coroutine.wrap}, |
1560 | then its corresponding function will close all variables | 1560 | then its corresponding function will close all variables |
@@ -6351,6 +6351,18 @@ which come inside the table @defid{coroutine}. | |||
6351 | See @See{coroutine} for a general description of coroutines. | 6351 | See @See{coroutine} for a general description of coroutines. |
6352 | 6352 | ||
6353 | 6353 | ||
6354 | @LibEntry{coroutine.close (co)| | ||
6355 | |||
6356 | Closes coroutine @id{co}, | ||
6357 | that is, | ||
6358 | closes all its pending to-be-closed variables | ||
6359 | and puts the coroutine in a dead state. | ||
6360 | In case of error closing some variable, | ||
6361 | returns @false plus the error object; | ||
6362 | otherwise returns @true. | ||
6363 | |||
6364 | } | ||
6365 | |||
6354 | @LibEntry{coroutine.create (f)| | 6366 | @LibEntry{coroutine.create (f)| |
6355 | 6367 | ||
6356 | Creates a new coroutine, with body @id{f}. | 6368 | Creates a new coroutine, with body @id{f}. |
@@ -6370,17 +6382,6 @@ it is not inside a non-yieldable @N{C function}. | |||
6370 | 6382 | ||
6371 | } | 6383 | } |
6372 | 6384 | ||
6373 | @LibEntry{coroutine.kill (co)| | ||
6374 | |||
6375 | Kills coroutine @id{co}, | ||
6376 | closing all its pending to-be-closed variables | ||
6377 | and putting the coroutine in a dead state. | ||
6378 | In case of error closing some variable, | ||
6379 | returns @false plus the error object; | ||
6380 | otherwise returns @true. | ||
6381 | |||
6382 | } | ||
6383 | |||
6384 | @LibEntry{coroutine.resume (co [, val1, @Cdots])| | 6385 | @LibEntry{coroutine.resume (co [, val1, @Cdots])| |
6385 | 6386 | ||
6386 | Starts or continues the execution of coroutine @id{co}. | 6387 | Starts or continues the execution of coroutine @id{co}. |
@@ -6433,7 +6434,7 @@ extra arguments to @id{resume}. | |||
6433 | The function returns the same values returned by @id{resume}, | 6434 | The function returns the same values returned by @id{resume}, |
6434 | except the first boolean. | 6435 | except the first boolean. |
6435 | In case of error, | 6436 | In case of error, |
6436 | the function kills the coroutine and propagates the error. | 6437 | the function closes the coroutine and propagates the error. |
6437 | 6438 | ||
6438 | } | 6439 | } |
6439 | 6440 | ||
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index db6d074e..198a5870 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -123,23 +123,23 @@ assert(#a == 22 and a[#a] == 79) | |||
123 | x, a = nil | 123 | x, a = nil |
124 | 124 | ||
125 | 125 | ||
126 | -- coroutine kill | 126 | -- coroutine closing |
127 | do | 127 | do |
128 | -- ok to kill a dead coroutine | 128 | -- ok to close a dead coroutine |
129 | local co = coroutine.create(print) | 129 | local co = coroutine.create(print) |
130 | assert(coroutine.resume(co, "testing 'coroutine.kill'")) | 130 | assert(coroutine.resume(co, "testing 'coroutine.close'")) |
131 | assert(coroutine.status(co) == "dead") | 131 | assert(coroutine.status(co) == "dead") |
132 | assert(coroutine.kill(co)) | 132 | assert(coroutine.close(co)) |
133 | 133 | ||
134 | -- cannot kill the running coroutine | 134 | -- cannot close the running coroutine |
135 | local st, msg = pcall(coroutine.kill, coroutine.running()) | 135 | local st, msg = pcall(coroutine.close, coroutine.running()) |
136 | assert(not st and string.find(msg, "running")) | 136 | assert(not st and string.find(msg, "running")) |
137 | 137 | ||
138 | local main = coroutine.running() | 138 | local main = coroutine.running() |
139 | 139 | ||
140 | -- cannot kill a "normal" coroutine | 140 | -- cannot close a "normal" coroutine |
141 | ;(coroutine.wrap(function () | 141 | ;(coroutine.wrap(function () |
142 | local st, msg = pcall(coroutine.kill, main) | 142 | local st, msg = pcall(coroutine.close, main) |
143 | assert(not st and string.find(msg, "normal")) | 143 | assert(not st and string.find(msg, "normal")) |
144 | end))() | 144 | end))() |
145 | 145 | ||
@@ -159,10 +159,10 @@ do | |||
159 | end) | 159 | end) |
160 | coroutine.resume(co) | 160 | coroutine.resume(co) |
161 | assert(X) | 161 | assert(X) |
162 | assert(coroutine.kill(co)) | 162 | assert(coroutine.close(co)) |
163 | assert(not X and coroutine.status(co) == "dead") | 163 | assert(not X and coroutine.status(co) == "dead") |
164 | 164 | ||
165 | -- error killing a coroutine | 165 | -- error closing a coroutine |
166 | co = coroutine.create(function() | 166 | co = coroutine.create(function() |
167 | local <toclose> x = func2close(function (self, err) | 167 | local <toclose> x = func2close(function (self, err) |
168 | assert(err == nil); error(111) | 168 | assert(err == nil); error(111) |
@@ -170,7 +170,7 @@ do | |||
170 | coroutine.yield() | 170 | coroutine.yield() |
171 | end) | 171 | end) |
172 | coroutine.resume(co) | 172 | coroutine.resume(co) |
173 | local st, msg = coroutine.kill(co) | 173 | local st, msg = coroutine.close(co) |
174 | assert(not st and coroutine.status(co) == "dead" and msg == 111) | 174 | assert(not st and coroutine.status(co) == "dead" and msg == 111) |
175 | 175 | ||
176 | end | 176 | end |