-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyield.lua
More file actions
29 lines (29 loc) · 809 Bytes
/
yield.lua
File metadata and controls
29 lines (29 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local function count(kvs)
for _, i in range(merge_kwargs({}, {}), 10) do
coroutine.yield(i)
::loop_label_1::
end
end
count = meta_generator({}, count)
local c = count(merge_kwargs({}, {}))
assert(bool({}, (next(merge_kwargs({}, {}), c) == 0)))
assert(bool({}, (next(merge_kwargs({}, {}), c) == 1)))
assert(bool({}, (next(merge_kwargs({}, {}), c) == 2)))
local function echo(kvs)
local start = nil
while bool({}, true) do
local line = coroutine.yield(start)
start = line
::loop_label_2::
end
end
echo = meta_generator({}, echo)
local e = echo(merge_kwargs({}, {}))
assert(bool({}, (next(merge_kwargs({}, {}), e) == nil)))
assert(bool({}, (e.send(merge_kwargs({}, {}), 10) == 10)))
return {
count = count,
c = c,
echo = echo,
e = e,
}