|
发表于 2009-5-31 18:59:31
|
显示全部楼层
俺头一回见识coroutine,不知道有没有同步机制,类似synchronize的
用最笨的,外层递归轮循监视内层递归是否完成,若完成则继续,否则等待
这已经离所谓的并发越来越远了。。。囧
taoyuan,beijing,huyidao,wudang测试通过
temp_thread_path = {}
function exec_alias(s)
temp_thread_path=coroutine.create(function (s)
Note ("create coroutine : ", s)
local p_temp = Split(s,";");
for i,v in ipairs(p_temp) do
if alias_table[v] then
exec_alias (alias_table[v], s)
Note ("before yield")
while temp_thread_path[alias_table[v]] do
Note ("before yield ", temp_thread_path[alias_table[v]])
DoAfterSpecial (1, "resume_coroutine(\""..s.."\")", 12)
coroutine.yield ()
end
elseif nil~=string.find(v,"#%d+ ") then
world.Send(do_table[string.sub(v,string.find(v,"#%d+ "))]..string.sub(v,string.find(v," .+")));
elseif nil~=string.find(v,"#wa") then
world.DoAfterSpecial(string.sub(v,string.find(v,"%d+")) / 2000,"resume_coroutine(\""..s.."\")",12);
coroutine.yield();
else
world.Send(v);
end
end
Note ("coroutine end : ", s)
temp_thread_path = nil
end)
coroutine.resume(temp_thread_path,s);
end
function resume_coroutine (thread_name)
Note ("resume_coroutine : ", thread_name)
coroutine.resume(temp_thread_path[thread_name]);
end
[ 本帖最后由 duno 于 2009-5-31 07:01 PM 编辑 ] |
|