diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-10 13:23:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-10 13:23:14 -0300 |
commit | a93e0144479f1eb0ac19b8c31862f4cbc2fbe1c4 (patch) | |
tree | da550c2f101ae33b6a068936c5dc77064abf3951 /testes/coroutine.lua | |
parent | 8ba4523cccf59093543cec988b07957193d55692 (diff) | |
download | lua-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.lua | 7 |
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 | |||
10 | local main, ismain = coroutine.running() | 10 | local main, ismain = coroutine.running() |
11 | assert(type(main) == "thread" and ismain) | 11 | assert(type(main) == "thread" and ismain) |
12 | assert(not coroutine.resume(main)) | 12 | assert(not coroutine.resume(main)) |
13 | assert(not coroutine.isyieldable()) | 13 | assert(not coroutine.isyieldable(main) and not coroutine.isyieldable()) |
14 | assert(not pcall(coroutine.yield)) | 14 | assert(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, ...) | |||
46 | end | 46 | end |
47 | 47 | ||
48 | f = coroutine.create(foo) | 48 | f = coroutine.create(foo) |
49 | assert(coroutine.isyieldable(f)) | ||
49 | assert(type(f) == "thread" and coroutine.status(f) == "suspended") | 50 | assert(type(f) == "thread" and coroutine.status(f) == "suspended") |
50 | assert(string.find(tostring(f), "thread")) | 51 | assert(string.find(tostring(f), "thread")) |
51 | local s,a,b,c,d | 52 | local s,a,b,c,d |
52 | s,a,b,c,d = coroutine.resume(f, {1,2,3}, {}, {1}, {'a', 'b', 'c'}) | 53 | s,a,b,c,d = coroutine.resume(f, {1,2,3}, {}, {1}, {'a', 'b', 'c'}) |
54 | assert(coroutine.isyieldable(f)) | ||
53 | assert(s and a == nil and coroutine.status(f) == "suspended") | 55 | assert(s and a == nil and coroutine.status(f) == "suspended") |
54 | s,a,b,c,d = coroutine.resume(f) | 56 | s,a,b,c,d = coroutine.resume(f) |
55 | eqtab(_G.x, {}) | 57 | eqtab(_G.x, {}) |
56 | assert(s and a == 1 and b == nil) | 58 | assert(s and a == 1 and b == nil) |
59 | assert(coroutine.isyieldable(f)) | ||
57 | s,a,b,c,d = coroutine.resume(f, 1, 2, 3) | 60 | s,a,b,c,d = coroutine.resume(f, 1, 2, 3) |
58 | eqtab(_G.x, {1, 2, 3}) | 61 | eqtab(_G.x, {1, 2, 3}) |
59 | assert(s and a == 'a' and b == 'b' and c == 'c' and d == nil) | 62 | assert(s and a == 'a' and b == 'b' and c == 'c' and d == nil) |