Initial draft of coroutines library.

This commit is contained in:
James Roseborough
2007-10-20 00:51:15 +00:00
parent 8e2ff119f9
commit 78eaaf0fa0
8 changed files with 233 additions and 4 deletions

View File

@@ -60,6 +60,10 @@ public class LuaJTest extends TestCase {
runTest( "coercions" );
}
public void testCoroutines() throws IOException, InterruptedException {
runTest( "coroutines" );
}
public void testCompare() throws IOException, InterruptedException {
runTest( "compare" );
}

View File

@@ -0,0 +1,18 @@
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)
print("co-body", r)
local r, s = coroutine.yield(a+b, a-b)
print("co-body", r, s)
return b, "end"
end)
print("main", coroutine.resume(co, 1, 10))
print("main", coroutine.resume(co, "r"))
print("main", coroutine.resume(co, "x", "y"))
print("main", coroutine.resume(co, "x", "y"))

Binary file not shown.