Initial draft of coroutines library.
This commit is contained in:
@@ -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" );
|
||||
}
|
||||
|
||||
18
src/test/res/coroutines.lua
Normal file
18
src/test/res/coroutines.lua
Normal 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"))
|
||||
BIN
src/test/res/coroutines.luac
Normal file
BIN
src/test/res/coroutines.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user