aboutsummaryrefslogtreecommitdiff
path: root/testes/coroutine.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-10 13:23:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-10 13:23:14 -0300
commita93e0144479f1eb0ac19b8c31862f4cbc2fbe1c4 (patch)
treeda550c2f101ae33b6a068936c5dc77064abf3951 /testes/coroutine.lua
parent8ba4523cccf59093543cec988b07957193d55692 (diff)
downloadlua-a93e0144479f1eb0ac19b8c31862f4cbc2fbe1c4.tar.gz
lua-a93e0144479f1eb0ac19b8c31862f4cbc2fbe1c4.tar.bz2
lua-a93e0144479f1eb0ac19b8c31862f4cbc2fbe1c4.zip
Added an optional parameter to 'coroutine.isyieldable'
Diffstat (limited to 'testes/coroutine.lua')
-rw-r--r--testes/coroutine.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index a4321bed..35ff27fb 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -10,7 +10,7 @@ local f
10local main, ismain = coroutine.running() 10local main, ismain = coroutine.running()
11assert(type(main) == "thread" and ismain) 11assert(type(main) == "thread" and ismain)
12assert(not coroutine.resume(main)) 12assert(not coroutine.resume(main))
13assert(not coroutine.isyieldable()) 13assert(not coroutine.isyieldable(main) and not coroutine.isyieldable())
14assert(not pcall(coroutine.yield)) 14assert(not pcall(coroutine.yield))
15 15
16 16
@@ -38,7 +38,7 @@ function foo (a, ...)
38 assert(coroutine.resume(f) == false) 38 assert(coroutine.resume(f) == false)
39 assert(coroutine.status(f) == "running") 39 assert(coroutine.status(f) == "running")
40 local arg = {...} 40 local arg = {...}
41 assert(coroutine.isyieldable()) 41 assert(coroutine.isyieldable(x))
42 for i=1,#arg do 42 for i=1,#arg do
43 _G.x = {coroutine.yield(table.unpack(arg[i]))} 43 _G.x = {coroutine.yield(table.unpack(arg[i]))}
44 end 44 end
@@ -46,14 +46,17 @@ function foo (a, ...)
46end 46end
47 47
48f = coroutine.create(foo) 48f = coroutine.create(foo)
49assert(coroutine.isyieldable(f))
49assert(type(f) == "thread" and coroutine.status(f) == "suspended") 50assert(type(f) == "thread" and coroutine.status(f) == "suspended")
50assert(string.find(tostring(f), "thread")) 51assert(string.find(tostring(f), "thread"))
51local s,a,b,c,d 52local s,a,b,c,d
52s,a,b,c,d = coroutine.resume(f, {1,2,3}, {}, {1}, {'a', 'b', 'c'}) 53s,a,b,c,d = coroutine.resume(f, {1,2,3}, {}, {1}, {'a', 'b', 'c'})
54assert(coroutine.isyieldable(f))
53assert(s and a == nil and coroutine.status(f) == "suspended") 55assert(s and a == nil and coroutine.status(f) == "suspended")
54s,a,b,c,d = coroutine.resume(f) 56s,a,b,c,d = coroutine.resume(f)
55eqtab(_G.x, {}) 57eqtab(_G.x, {})
56assert(s and a == 1 and b == nil) 58assert(s and a == 1 and b == nil)
59assert(coroutine.isyieldable(f))
57s,a,b,c,d = coroutine.resume(f, 1, 2, 3) 60s,a,b,c,d = coroutine.resume(f, 1, 2, 3)
58eqtab(_G.x, {1, 2, 3}) 61eqtab(_G.x, {1, 2, 3})
59assert(s and a == 'a' and b == 'b' and c == 'c' and d == nil) 62assert(s and a == 'a' and b == 'b' and c == 'c' and d == nil)