|
楼主 |
发表于 2011-9-13 09:54:04
|
显示全部楼层
牵扯到的其他部分
busy={
interval=0.1,
timeout=10,
new=function()
local b={}
setmetatable(b,{__index=busy})
return b
end,
}
function busy:Next() -- 接口函数
end
function busy:check()
wait.make(function()
world.Execute("halt;set busy")
local l,w=wait.regexp("^(> |)你现在不忙。$|^(> |)设定环境变量:busy \\= \\\"YES\\\"$",self.timeout) --超时
if l==nil then
print "网络太慢或是发生了一个非预期的错误"
self:check()
return
end
if string.find(l,"你现在不忙") then
self:Next()
return
end
if string.find(l,"设定环境变量:busy") then
local f=function() self:check() end
f_wait(f,self.interval)
return
end
wait(self.timeout) --timeout
end)
end
-- 在脚本中调用这个函数来暂停当前的线程
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 -- function wait
[ 本帖最后由 onlinego 于 2011-9-13 07:12 PM 编辑 ] |
|