[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Reload a script file with coroutine
- From: "jiang.yu\(mos\)" <mmosquito@...>
- Date: Fri, 11 May 2007 15:13:13 +0800
Hi!
In my project each script file associated with a lua_state like:
std::map<std::string,lua_State*> ScriptMap
and the ScriptEngine have a function ClearScriptFile like
void ClearScriptFile(string file)
{
itScript it = m_mapScript.find(file);
m_mapScript.erase(it);
lua_close(it->second);
}
Normally it works ok, but if the script use coroutine like:
function main()
co = coroutine.create(function ()
testyield()
end)
print(coroutine.resume(co))
end
function testyield()
YieldSleep(10000)
end
YieldSleep is a C function:
int YieldSleep(lua_State* L)
{
int time = lua_tonumber(L,1);
AddYieldSleep(L,time); // Add a timer and use L as param.
return lua_yield(L,0);
}
and the OnTimer:
DWORD OnTimer(DWORD idTimer)
{
lua_State* L = (lua_State*)idTimer;
lua_resume(L,0);
}
Then after ClearScriptFile when OnTimer call lua_resume(L,0) the program
crash.
So is there any way to handle it ?
Best Regard.
Mos.
Best Regards
mos