Fix coroutine error handling.
This commit is contained in:
@@ -142,10 +142,11 @@ public class LThread extends LValue implements Runnable {
|
|||||||
|
|
||||||
// copy return values from yielding stack state
|
// copy return values from yielding stack state
|
||||||
vm.resettop();
|
vm.resettop();
|
||||||
vm.pushboolean(true);
|
|
||||||
if ( threadVm.cc >= 0 ) {
|
if ( threadVm.cc >= 0 ) {
|
||||||
|
vm.pushboolean(status != STATUS_DEAD);
|
||||||
threadVm.xmove(vm, threadVm.gettop() - 1);
|
threadVm.xmove(vm, threadVm.gettop() - 1);
|
||||||
} else {
|
} else {
|
||||||
|
vm.pushboolean(true);
|
||||||
threadVm.base = 0;
|
threadVm.base = 0;
|
||||||
threadVm.xmove(vm, threadVm.gettop());
|
threadVm.xmove(vm, threadVm.gettop());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,16 @@ checkallerrors('coroutine.wrap',{notafunction},'bad argument #1')
|
|||||||
banner('coroutine.yield')
|
banner('coroutine.yield')
|
||||||
local function f()
|
local function f()
|
||||||
print( 'yield', coroutine.yield() )
|
print( 'yield', coroutine.yield() )
|
||||||
print( 'yield', coroutine.yield(astring) )
|
print( 'yield', coroutine.yield(astring,anumber,aboolean) )
|
||||||
print( 'yield', coroutine.yield(anumber) )
|
error('error within coroutine thread')
|
||||||
print( 'yield', coroutine.yield(aboolean) )
|
|
||||||
end
|
end
|
||||||
local co = coroutine.create( f )
|
local co = coroutine.create( f )
|
||||||
repeat
|
print( 'status', coroutine.status(co) )
|
||||||
print( 'resume', coroutine.resume(co,astring,anumber) )
|
print( coroutine.resume(co,astring,anumber) )
|
||||||
until coroutine.status(co) ~= 'suspended'
|
print( 'status', coroutine.status(co) )
|
||||||
|
print( coroutine.resume(co,astring,anumber) )
|
||||||
|
print( 'status', coroutine.status(co) )
|
||||||
|
local s,e = coroutine.resume(co,astring,anumber)
|
||||||
|
print( s, string.match(e,'error within coroutine thread') or 'bad message: '..tostring(e) )
|
||||||
|
print( 'status', coroutine.status(co) )
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ exercise();
|
|||||||
|
|
||||||
co = coroutine.create(function (a,b)
|
co = coroutine.create(function (a,b)
|
||||||
print("co-body", a, b)
|
print("co-body", a, b)
|
||||||
local status,r = pcall( foo, a+1 )
|
-- TODO: make java and C behave the same for yielding in pcalls
|
||||||
|
-- local status,r = pcall( foo, a+1 )
|
||||||
|
foo(a+1)
|
||||||
print("co-body", status,r)
|
print("co-body", status,r)
|
||||||
local r, s = coroutine.yield(a+b, a-b)
|
local r, s = coroutine.yield(a+b, a-b)
|
||||||
print("co-body", r, s)
|
print("co-body", r, s)
|
||||||
@@ -69,5 +71,6 @@ end )
|
|||||||
print("g", g(1, 10))
|
print("g", g(1, 10))
|
||||||
print("g", g("r"))
|
print("g", g("r"))
|
||||||
print("g", g("x", "y"))
|
print("g", g("x", "y"))
|
||||||
print("g", pcall( g, "x", "y" ))
|
local s,e = pcall( g, "x", "y" )
|
||||||
|
print("g", string.match(e,'cannot resume dead coroutine') or 'badmessage: '..tostring(e))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user