Bug: Yielding in a hook stops in the wrong instruction
Yielding in a hook must decrease the program counter, because it already counted an instruction that, in the end, was not executed. However, that decrement should be done only when about to restart the thread. Otherwise, inspecting the thread with the debug library shows it one instruction behind of where it really is.
This commit is contained in:
@@ -610,18 +610,20 @@ else
|
||||
-- (bug in 5.2/5.3)
|
||||
c = coroutine.create(function (a, ...)
|
||||
T.sethook("yield 0", "l") -- will yield on next two lines
|
||||
assert(a == 10)
|
||||
local b = a
|
||||
return ...
|
||||
end)
|
||||
|
||||
assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine
|
||||
local n,v = debug.getlocal(c, 0, 1) -- check its local
|
||||
assert(n == "a" and v == 1)
|
||||
assert(n == "a" and v == 1 and debug.getlocal(c, 0, 2) ~= "b")
|
||||
assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal'
|
||||
local t = debug.getinfo(c, 0) -- test 'getinfo'
|
||||
assert(t.currentline == t.linedefined + 1)
|
||||
assert(t.currentline == t.linedefined + 2)
|
||||
assert(not debug.getinfo(c, 1)) -- no other level
|
||||
assert(coroutine.resume(c)) -- run next line
|
||||
local n,v = debug.getlocal(c, 0, 2) -- check next local
|
||||
assert(n == "b" and v == 10)
|
||||
v = {coroutine.resume(c)} -- finish coroutine
|
||||
assert(v[1] == true and v[2] == 2 and v[3] == 3 and v[4] == undef)
|
||||
assert(not coroutine.resume(c))
|
||||
|
||||
Reference in New Issue
Block a user