....前面是du book,然后等读完
local l,w=wait.regexp("^[>\\s]*你(?:研读完毕|收起手上的)",300)
if l~=nil and string.find(l,"研读完毕") then
print("OK,成功")
end
循环体中这样一个chunk,在执行中,当研读完毕时,有时打印出成功,有时明明是研读完毕却没打印出来。显然是哪个地方出了问题,为了跟踪问题,我修改了wait.lua,将wait中的trigger_resume改成这样子。
function trigger_resume (name, line, wildcards, styles)
local thread = threads [name]
if thread then
threads [name] = nil
local ok, err = coroutine.resume (thread, line, wildcards, styles)
if not ok then
ColourNote ("deeppink", "black", "Error raised in trigger function (in wait module)")
ColourNote ("darkorange", "black", debug.traceback (thread))
error (err)
end -- if
else
print(name," resume, got \"",thread,"\" thread")
end -- if
end -- function trigger_resume
你猜怎么着,嘿,当出现问题时,还真打印出来 wait_trigger_1884065 resume, got " nil " thread。也就是说,当这个trigger被触发,需要resume时,找不到这个线程了。找不到线程,自然就执行不下去了。什么原因呢? |