-----------------------------------------------------------------
-- ½Å±¾Èë¿Ú´¦

math.randomseed(os.clock()*1000)



-- Simple Coroutines System
moc = {}
moc.co_list_ = {}



function moc.createCo(f)
	local cc = coroutine.create(f)
	print("create coroutine ["..tostring(cc).."]¡¢")
	table.insert(moc.co_list_,{cc})
end

function moc.sleep(time)
	if time~=nil then
		local co = moc.running
		co.wake_time = moc.now + time
	end
	coroutine.yield()
end

function moc.run()
	local tt = moc.co_list_
	moc.co_list_ = {}
	for i,v in pairs(tt) do
		if v.wake_time~=nil then
			if moc.now>=v.wake_time then
				moc.running = v
				coroutine.resume(v[1])
			end
		else
			moc.running = v
			coroutine.resume(v[1])
		end
		if coroutine.status(v[1])~='dead' then
			table.insert(moc.co_list_,v)
		else
			print("coroutine dead ["..tostring(v[1]).."]¡¢")
		end
	end
end


-- this function for C use
function LFRunOnce(time_now)
	moc.now = time_now
	moc.run()
end

dofile(getRootPath().."/Scripts/aiml.lua")
dofile(getRootPath().."/Scripts/default_msg.lua")
dofile(getRootPath().."/Scripts/dict.lua")
dofile(getRootPath().."/Scripts/message.lua")
dofile(getRootPath().."/Scripts/group.lua")
dofile(getRootPath().."/Scripts/chat_log.lua")
