Coroutine implementation based on Java Threads.

This commit is contained in:
James Roseborough
2007-10-23 21:24:49 +00:00
parent c311c31a74
commit b86e06ab1c
4 changed files with 103 additions and 66 deletions

View File

@@ -10,7 +10,7 @@ function foo (a)
print("foo", a)
return coroutine.yield(2*a)
end
co = coroutine.create(function (a,b)
print("co-body", a, b)
local r = foo(a+1)
@@ -46,7 +46,7 @@ exercise();
co = coroutine.create(function (a,b)
print("co-body", a, b)
local statis,r = pcall( foo, a+1 )
local status,r = pcall( foo, a+1 )
print("co-body", status,r)
local r, s = coroutine.yield(a+b, a-b)
print("co-body", r, s)
@@ -55,6 +55,7 @@ end)
exercise();
-- wrap test
local g = coroutine.wrap(function (a,b)
print("co-body", a, b)