summaryrefslogtreecommitdiff
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-github-514d94274853e6f0dfd6bb2ffa2e1fc64db926dd.tar.gz
'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) {
}
-static int luaB_kill (lua_State *L) {
+static int luaB_close (lua_State *L) {
lua_State *co = getco(L);
int status = auxstatus(L, co);
switch (status) {
@@ -182,7 +182,7 @@ static int luaB_kill (lua_State *L) {
}
}
default: /* normal or running coroutine */
- return luaL_error(L, "cannot kill a %s coroutine", statname[status]);
+ return luaL_error(L, "cannot close a %s coroutine", statname[status]);
}
}
@@ -195,7 +195,7 @@ static const luaL_Reg co_funcs[] = {
{"wrap", luaB_cowrap},
{"yield", luaB_yield},
{"isyieldable", luaB_yieldable},
- {"kill", luaB_kill},
+ {"close", luaB_close},
{NULL, NULL}
};
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},
the function created by @Lid{coroutine.wrap}
propagates any error to the caller.
In this case,
-the function also kills the coroutine @seeF{coroutine.kill}.
+the function also closes the coroutine @seeF{coroutine.close}.
As an example of how coroutines work,
consider the following code:
@@ -1554,7 +1554,7 @@ Similarly, if a coroutine ends with an error,
it does not unwind its stack,
so it does not close any variable.
You should either use finalizers
-or call @Lid{coroutine.kill} to close the variables in these cases.
+or call @Lid{coroutine.close} to close the variables in these cases.
However, note that if the coroutine was created
through @Lid{coroutine.wrap},
then its corresponding function will close all variables
@@ -6351,6 +6351,18 @@ which come inside the table @defid{coroutine}.
See @See{coroutine} for a general description of coroutines.
+@LibEntry{coroutine.close (co)|
+
+Closes coroutine @id{co},
+that is,
+closes all its pending to-be-closed variables
+and puts the coroutine in a dead state.
+In case of error closing some variable,
+returns @false plus the error object;
+otherwise returns @true.
+
+}
+
@LibEntry{coroutine.create (f)|
Creates a new coroutine, with body @id{f}.
@@ -6370,17 +6382,6 @@ it is not inside a non-yieldable @N{C function}.
}
-@LibEntry{coroutine.kill (co)|
-
-Kills coroutine @id{co},
-closing all its pending to-be-closed variables
-and putting the coroutine in a dead state.
-In case of error closing some variable,
-returns @false plus the error object;
-otherwise returns @true.
-
-}
-
@LibEntry{coroutine.resume (co [, val1, @Cdots])|
Starts or continues the execution of coroutine @id{co}.
@@ -6433,7 +6434,7 @@ extra arguments to @id{resume}.
The function returns the same values returned by @id{resume},
except the first boolean.
In case of error,
-the function kills the coroutine and propagates the error.
+the function closes the coroutine and propagates the error.
}
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)
x, a = nil
--- coroutine kill
+-- coroutine closing
do
- -- ok to kill a dead coroutine
+ -- ok to close a dead coroutine
local co = coroutine.create(print)
- assert(coroutine.resume(co, "testing 'coroutine.kill'"))
+ assert(coroutine.resume(co, "testing 'coroutine.close'"))
assert(coroutine.status(co) == "dead")
- assert(coroutine.kill(co))
+ assert(coroutine.close(co))
- -- cannot kill the running coroutine
- local st, msg = pcall(coroutine.kill, coroutine.running())
+ -- cannot close the running coroutine
+ local st, msg = pcall(coroutine.close, coroutine.running())
assert(not st and string.find(msg, "running"))
local main = coroutine.running()
- -- cannot kill a "normal" coroutine
+ -- cannot close a "normal" coroutine
;(coroutine.wrap(function ()
- local st, msg = pcall(coroutine.kill, main)
+ local st, msg = pcall(coroutine.close, main)
assert(not st and string.find(msg, "normal"))
end))()
@@ -159,10 +159,10 @@ do
end)
coroutine.resume(co)
assert(X)
- assert(coroutine.kill(co))
+ assert(coroutine.close(co))
assert(not X and coroutine.status(co) == "dead")
- -- error killing a coroutine
+ -- error closing a coroutine
co = coroutine.create(function()
local <toclose> x = func2close(function (self, err)
assert(err == nil); error(111)
@@ -170,7 +170,7 @@ do
coroutine.yield()
end)
coroutine.resume(co)
- local st, msg = coroutine.kill(co)
+ local st, msg = coroutine.close(co)
assert(not st and coroutine.status(co) == "dead" and msg == 111)
end