aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-03 13:11:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-03 13:11:20 -0300
commit514d94274853e6f0dfd6bb2ffa2e1fc64db926dd (patch)
treee024ebca966e8a84a7997c3908b74bb941dcbd50
parent4a3fd8488d617aa633f6b8be85e662653b100a59 (diff)
downloadlua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.tar.gz
lua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.tar.bz2
lua-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.zip
'coroutine.kill' renamed 'coroutine.close'
-rw-r--r--lcorolib.c6
-rw-r--r--manual/manual.of29
-rw-r--r--testes/coroutine.lua22
3 files changed, 29 insertions, 28 deletions
diff --git a/lcorolib.c b/lcorolib.c
index 3fc9fb1c..156839e6 100644
--- a/lcorolib.c
+++ b/lcorolib.c
@@ -165,7 +165,7 @@ static int luaB_corunning (lua_State *L) {
165} 165}
166 166
167 167
168static int luaB_kill (lua_State *L) { 168static 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},
864the function created by @Lid{coroutine.wrap} 864the function created by @Lid{coroutine.wrap}
865propagates any error to the caller. 865propagates any error to the caller.
866In this case, 866In this case,
867the function also kills the coroutine @seeF{coroutine.kill}. 867the function also closes the coroutine @seeF{coroutine.close}.
868 868
869As an example of how coroutines work, 869As an example of how coroutines work,
870consider the following code: 870consider the following code:
@@ -1554,7 +1554,7 @@ Similarly, if a coroutine ends with an error,
1554it does not unwind its stack, 1554it does not unwind its stack,
1555so it does not close any variable. 1555so it does not close any variable.
1556You should either use finalizers 1556You should either use finalizers
1557or call @Lid{coroutine.kill} to close the variables in these cases. 1557or call @Lid{coroutine.close} to close the variables in these cases.
1558However, note that if the coroutine was created 1558However, note that if the coroutine was created
1559through @Lid{coroutine.wrap}, 1559through @Lid{coroutine.wrap},
1560then its corresponding function will close all variables 1560then its corresponding function will close all variables
@@ -6351,6 +6351,18 @@ which come inside the table @defid{coroutine}.
6351See @See{coroutine} for a general description of coroutines. 6351See @See{coroutine} for a general description of coroutines.
6352 6352
6353 6353
6354@LibEntry{coroutine.close (co)|
6355
6356Closes coroutine @id{co},
6357that is,
6358closes all its pending to-be-closed variables
6359and puts the coroutine in a dead state.
6360In case of error closing some variable,
6361returns @false plus the error object;
6362otherwise returns @true.
6363
6364}
6365
6354@LibEntry{coroutine.create (f)| 6366@LibEntry{coroutine.create (f)|
6355 6367
6356Creates a new coroutine, with body @id{f}. 6368Creates 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
6375Kills coroutine @id{co},
6376closing all its pending to-be-closed variables
6377and putting the coroutine in a dead state.
6378In case of error closing some variable,
6379returns @false plus the error object;
6380otherwise returns @true.
6381
6382}
6383
6384@LibEntry{coroutine.resume (co [, val1, @Cdots])| 6385@LibEntry{coroutine.resume (co [, val1, @Cdots])|
6385 6386
6386Starts or continues the execution of coroutine @id{co}. 6387Starts or continues the execution of coroutine @id{co}.
@@ -6433,7 +6434,7 @@ extra arguments to @id{resume}.
6433The function returns the same values returned by @id{resume}, 6434The function returns the same values returned by @id{resume},
6434except the first boolean. 6435except the first boolean.
6435In case of error, 6436In case of error,
6436the function kills the coroutine and propagates the error. 6437the 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)
123x, a = nil 123x, a = nil
124 124
125 125
126-- coroutine kill 126-- coroutine closing
127do 127do
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
176end 176end