|
楼主 |
发表于 2011-1-19 10:03:16
|
显示全部楼层
--f wait 函数
-- 线程表,储存正在暂停的线程
local wait_table = {}
--setmetatable(wait_table, {__mode = "v"}) --weak table
-- 被定时器调用以恢复一个暂停的线程
function wait_timer_resume(name)
--print(table.getn(wait_table))
--print("wait_id: ",name)
thread = wait_table[name]
if thread~=nil then
assert(coroutine.resume (thread))
else
print(name," 不存在")
end -- if
wait_table[name]={} --垃圾回收
end -- function wait_timer_resume
-- 在脚本中调用这个函数来暂停当前的线程
function f_wait(address, seconds)
id = "wait_timer_" .. GetUniqueNumber ()
hours = math.floor(seconds / 3600)
seconds = seconds - (hours * 3600)
minutes = math.floor(seconds / 60)
seconds = seconds - (minutes * 60)
--print("等待",seconds,"s"," ",id)
wait_table[id] =coroutine.create(function()
-- print("执行")
address()
end)
status = AddTimer (id, hours, minutes, seconds, "",
timer_flag.Enabled + timer_flag.OneShot +
timer_flag.Temporary + timer_flag.Replace,
"wait_timer_resume")
assert(status == error_code.eOK, error_desc[status])
end |
|