aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 29cb05d5..076f6361 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -764,4 +764,25 @@ for k,v in ipairs(a) do
764end 764end
765assert(i == a.n) 765assert(i == a.n)
766 766
767
768-- testing yield inside __pairs
769do
770 local t = setmetatable({10, 20, 30}, {__pairs = function (t)
771 local inc = coroutine.yield()
772 return function (t, i)
773 if i > 1 then return i - inc, t[i - inc] else return nil end
774 end, t, #t + 1
775 end})
776
777 local res = {}
778 local co = coroutine.wrap(function ()
779 for i,p in pairs(t) do res[#res + 1] = p end
780 end)
781
782 co() -- start coroutine
783 co(1) -- continue after yield
784 assert(res[1] == 30 and res[2] == 20 and res[3] == 10 and #res == 3)
785
786end
787
767print"OK" 788print"OK"