LUA程序设计第4版第24章练习答案
程序员文章站
2024-03-17 23:09:58
...
f24.1 生产者设计驱动模式
function producer()
while true do
local x = io.read()
send(x)
end
end
function consumer(x)
print(x)
while true do
print(receive())
end
end
function send(x)
coroutine.resume(consumer,x)
end
function receive()
return coroutine.yield()
end
consumer = coroutine.create(consumer)
producer()