lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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